ÔõÑùÔÚ÷è÷ë²Ù×÷ϵͳÉϾÙÐÐͼƬºÍÕÕƬµÄ±à¼ºÍ´¦Àí£¿
ÔõÑùÔÚ÷è÷ë²Ù×÷ϵͳÉϾÙÐÐͼƬºÍÕÕƬµÄ±à¼ºÍ´¦Àí£¿
÷è÷ë²Ù×÷ϵͳÊÇÖйú×ÔÖ÷Ñз¢µÄÒ»ÖÖ»ùÓÚLinuxµÄ×ÔÓɲÙ×÷ϵͳ¡£ËüÖ§³Ö¶àÖÖÓ²¼þƽ̨£¬²¢ÌṩÁ˸»ºñµÄ¹¦Ð§ºÍ¹¤¾ß¡£ÆäÖÐÒ»¸öÖ÷ÒªµÄ¹¦Ð§¾ÍÊÇͼƬºÍÕÕƬµÄ±à¼ºÍ´¦Àí¡£ÏÂÃ潫ÏÈÈÝÔÚ÷è÷ë²Ù×÷ϵͳÉÏÔõÑù¾ÙÐÐͼƬºÍÕÕƬµÄ±à¼ºÍ´¦Àí£¬²¢ÌṩÏìÓ¦µÄ´úÂëʾÀý¡£
Ê×ÏÈ£¬ÎÒÃÇÐèҪװÖÃһЩͼÏñ´¦ÀíºÍ±à¼µÄ¹¤¾ß¡£ÔÚ÷è÷ë²Ù×÷ϵͳÖУ¬ÎÒÃÇ¿ÉÒÔʹÓÃGIMP£¨GNU Image Manipulation Program£©À´¾ÙÐÐͼÏñµÄ±à¼ºÍ´¦Àí¡£GIMP ÊÇÒ»¿î¹¦Ð§Ç¿Ê¢¡¢Ãâ·ÑÇÒ¿ªÔ´µÄͼÏñ´¦ÀíÈí¼þ£¬¿ÉÒÔÖª×ãÖÖÖÖͼÏñ´¦ÀíÐèÇó¡£
ҪװÖÃGIMP£¬·¿ªÖն˲¢ÊäÈëÒÔÏÂÏÂÁ
sudo apt-get update sudo apt-get install gimp
µÇ¼ºó¸´ÖÆ
×°ÖÃÍê³Éºó£¬ÎÒÃǾͿÉÒÔʹÓÃGIMP¾ÙÐÐͼÏñµÄ±à¼ºÍ´¦ÀíÁË¡£
·¿ªÍ¼Ïñ
ÔÚGIMPµÄ²Ëµ¥À¸ÖУ¬Ñ¡Ôñ¡°Îļþ¡±->¡°·¿ª¡±£¬È»ºóÑ¡ÕªÒª±à¼µÄͼÏñÎļþ¡£GIMPÖ§³Ö¶àÖÖͼÏñÃûÌ㬰üÀ¨JPG¡¢PNG¡¢BMPµÈ¡£
ͼÏñµ÷½â
ÔÚGIMPµÄ¡°¹¤¾ßÏ䡱ÖУ¬Äã¿ÉÒÔÕÒµ½ÖÖÖÖ¹¤¾ßºÍÑ¡ÏîÀ´µ÷½âͼÏñ¡£ÀýÈ磬Äã¿ÉÒÔʹÓá°ÁÁ¶È/±ÈÕնȡ±¹¤¾ßÀ´µ÷½âͼÏñµÄÁÁ¶ÈºÍ±ÈÕնȣ¬Ê¹Óá°É«µ÷/±¥ºÍ¶È¡±¹¤¾ßÀ´µ÷½âͼÏñµÄɫе÷±¥ºÍ¶ÈµÈ¡£
ÒÔÏÂÊÇÒ»¸ö¼òÆӵĴúÂëʾÀý£¬ÑÝʾÔõÑùʹÓÃGIMPÀ´µ÷½âͼÏñµÄÁÁ¶ÈºÍ±ÈÕնȣº
import os import subprocess def adjust_image_brightness_contrast(image_path, brightness, contrast): try: command = f"gimp -i -b '(let* ((image (car (gimp-file-load RUN-NONINTERACTIVE "{image_path}" "{image_path}"))) (drawable (car (gimp-image-get-active-layer image)))) (gimp-image-undo-group-start image) (gimp-levels-stretch drawable 0 {brightness} {contrast}) (gimp-image-undo-group-end image) (gimp-file-save RUN-NONINTERACTIVE image drawable "{image_path}" "{image_path}") (gimp-image-delete image))' -b '(gimp-quit 0)'" subprocess.run(command, shell=True, check=True) return True except subprocess.CalledProcessError: return False image_path = "path/to/your/image.jpg" brightness = 50 contrast = 25 if adjust_image_brightness_contrast(image_path, brightness, contrast): print("Image adjusted successfully.") else: print("Failed to adjust image.")
µÇ¼ºó¸´ÖÆ
¸Ã´úÂëʹÓÃÁËGIMPµÄÏÂÁîÐнӿڣ¬ÏÈ·¿ªÖ¸¶¨µÄͼÏñÎļþ£¬È»ºóŲÓÃÁËgimp-levels-stretchº¯ÊýÀ´¾ÙÐÐÁÁ¶ÈºÍ±ÈÕնȵĵ÷½â£¬×îºóÉúÑIJ¢¹Ø±ÕͼÏñ¡£Äã¿ÉÒÔƾ֤ÐèÒª¸ü¸ÄÁÁ¶ÈºÍ±ÈÕնȵÄÖµ¡£
ͼÏñ²Ã¼ôºÍÐýת
GIMPÒ²ÌṩÁ˲üôºÍÐýתͼÏñµÄ¹¦Ð§¡£Äã¿ÉÒÔʹÓᰲüô¡±¹¤¾ßÀ´Ñ¡ÔñͼÏñÖиÐÐËȤµÄÇøÓò£¬²¢¼ô²Ã³öÀ´¡£Ê¹Óá°Ðýת¡±¹¤¾ß¿ÉÒÔ½«Í¼Ïñƾָ֤¶¨µÄ½Ç¶È¾ÙÐÐÐýת¡£
ÒÔÏÂÊÇÒ»¸ö¼òÆӵĴúÂëʾÀý£¬ÑÝʾÔõÑùʹÓÃGIMPÀ´²Ã¼ôºÍÐýתͼÏñ£º
import subprocess def crop_image(image_path, x, y, width, height): try: command = f"gimp -i -b '(let* ((image (car (gimp-file-load RUN-NONINTERACTIVE "{image_path}" "{image_path}"))) (drawable (car (gimp-image-get-active-layer image)))) (gimp-image-undo-group-start image) (gimp-image-crop image {width} {height} {x} {y}) (gimp-image-undo-group-end image) (gimp-file-save RUN-NONINTERACTIVE image drawable "{image_path}" "{image_path}") (gimp-image-delete image))' -b '(gimp-quit 0)'" subprocess.run(command, shell=True, check=True) return True except subprocess.CalledProcessError: return False def rotate_image(image_path, angle): try: command = f"gimp -i -b '(let* ((image (car (gimp-file-load RUN-NONINTERACTIVE "{image_path}" "{image_path}"))) (drawable (car (gimp-image-get-active-layer image)))) (gimp-image-undo-group-start image) (gimp-image-rotate image {angle}) (gimp-image-undo-group-end image) (gimp-file-save RUN-NONINTERACTIVE image drawable "{image_path}" "{image_path}") (gimp-image-delete image))' -b '(gimp-quit 0)'" subprocess.run(command, shell=True, check=True) return True except subprocess.CalledProcessError: return False image_path = "path/to/your/image.jpg" x = 100 y = 100 width = 200 height = 200 angle = 45 if crop_image(image_path, x, y, width, height): print("Image cropped successfully.") else: print("Failed to crop image.") if rotate_image(image_path, angle): print("Image rotated successfully.") else: print("Failed to rotate image.")
µÇ¼ºó¸´ÖÆ
¸Ã´úÂëʹÓÃÁËGIMPµÄÏÂÁîÐнӿڣ¬ÏÈ·¿ªÖ¸¶¨µÄͼÏñÎļþ£¬È»ºóŲÓÃÁËgimp-image-cropº¯ÊýÀ´¾ÙÐвüô£¬Å²ÓÃÁËgimp-image-rotateº¯ÊýÀ´¾ÙÐÐÐýת£¬×îºóÉúÑIJ¢¹Ø±ÕͼÏñ¡£Äã¿ÉÒÔƾ֤ÐèÒª¸ü¸Ä²Ã¼ôµÄ×ø±êºÍ³ß´çÒÔ¼°ÐýתµÄ½Ç¶È¡£
ͨ¹ýÒÔÉÏʾÀý£¬ÄãÒѾѧ»áÁËÔõÑùÔÚ÷è÷ë²Ù×÷ϵͳÉÏʹÓÃGIMP¾ÙÐÐͼƬºÍÕÕƬµÄ±à¼ºÍ´¦Àí¡£ÆñÂÛÊǵ÷½âÁÁ¶È±ÈÕնȡ¢²Ã¼ôÕÕ¾ÉÐýת£¬¶¼¿ÉÒÔͨ¹ý¼òÆӵĴúÂëʵÏÖ¡£ÒÔºó£¬Äã¿ÉÒÔΪËùÓûΪµØ±à¼ºÍ´¦ÀíÄãµÄͼƬºÍÕÕƬÁË£¡
ÒÔÉϾÍÊÇÔõÑùÔÚ÷è÷ë²Ù×÷ϵͳÉϾÙÐÐͼƬºÍÕÕƬµÄ±à¼ºÍ´¦Àí£¿µÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡