ÒÔPython Imaging Library ½øÐÐÓ°Ïñ×ÊÁÏ´¦ÀíPIL
1 Ó°ÏñÓëͼÐÎ×ÊÁϵĴ¦Àí
ÌÖÂÛͼÐÎ(Ó°Ïñ) ±¾ÉíµÄ´¦Àí£¬¶øÌÖÂÛµÄÄÚÈݽ«»á¼¯ÖÐÔÚPython Imaging Library (PIL) ÕâÒ»Ì׳Ìʽ¿âÉÏ¡£
PIL ÊÇPython ÏÂ×îÓÐÃûµÄÓ°Ïñ´¦ÀíÌ×¼þ£¬ÓÉÐí¶à²»Í¬µÄÄ£×éËù×é³É£¬²¢ÇÒÌṩÁËÐí¶àµÄ´¦Àí¹¦ÄÜ£¬ÔÊÐíÎÒÃÇÔÚ¼òµ¥µÄPython ³ÌʽÀï½øÐÐÓ°ÏñµÄ´¦Àí¡£ ʹÓÃÏñPIL ÐíÑùµÄ³Ìʽ¿âÌ×¼þ¿ÉÒÔ°ïÖúÎÒÃǰѾ«Á¦¼¯ÖÐÔÚÓ°Ïñ´¦ÀíµÄ¹¤×÷±¾Éí£¬±ÜÃâÃÔʧÔڵײãµÄÑÝËã·¨ÀïÃæ¡£
ÓÉÓÚÓ°Ïñ´¦ÀíÇ£Éæµ½ÁË´óÁ¿µÄÊýѧÔËË㣬Òò´ËPIL ÖÐÓÐÐí¶àµÄÄ£×éÊÇÓÃC ÓïÑÔËùд³ÉµÄ£¬ÒÔÌáÉý´¦ÀíµÄЧÂÊ¡£ ²»¹ý£¬ÔÚʹÓõÄʱºò£¬ÎÒÃǵ±È»²»±ØÔÚÒâÕâÑùµÄÎÊÌ⣬ֻ¹Ü·ÅÐĵØÓþÍÊÇÁË¡£
1.1 PIL ÄÜΪÄã×÷µÄÊÂ
PIL ¾ß±¸(µ«²»ÏÞÓÚ) ÒÔϵÄÄÜÁ¦£º
ÊýÊ®ÖÖͼµµ¸ñʽµÄ¶ÁдÄÜÁ¦¡£ ³£¼ûµÄJPEG, PNG, BMP, GIF, TIFF µÈ¸ñʽ£¬¶¼ÔÚPIL µÄÖ§Ô®Ö®ÁС£ ÁíÍ⣬PIL Ò²Ö§Ô®ºÚ°×¡¢»Ò½×¡¢×Ô¶©µ÷É«ÅÌ¡¢RGB true color¡¢´øÓÐ͸Ã÷ÊôÐÔµÄRBG true color¡¢CMYK ¼°ÆäËüÊýÖÖµÄÓ°Ïñģʽ¡£Ï൱ÆëÈ«¡£
»ù±¾µÄÓ°Ïñ×ÊÁϲÙ×÷£º²ÃÇС¢Æ½ÒÆ¡¢Ðýת¡¢¸Ä±ä³ß´ç¡¢µ÷ÖÃ(transpose)¡¢¼ôÏÂÓëÌùÉϵȵȡ£
Ç¿»¯Í¼ÐΣºÁÁ¶È¡¢É«µ÷¡¢¶Ô±È¡¢ÈñÀû¶È¡£
É«²Ê´¦Àí¡£
PIL ÌṩʮÊýÖÖÂ˾µ(filter)¡£ µ±È»£¬Õâ¸öÊýÄ¿Ô¶Ô¶²»ÄÜÓëPhotoshop® »òGIMP® ÕâÑùµÄרҵÌØЧ´¦ÀíÈíÌåÏà±È£»µ«PIL ÌṩµÄÕâЩÂ˾µ¿ÉÒÔÓÃÔÚPython ³ÌʽÀïÃ棬ÌṩÅú´Î»¯´¦ÀíµÄÄÜÁ¦¡£
PIL ¿ÉÒÔÔÚÓ°ÏñÖлæͼÖƵ㡢Ïß¡¢Ãæ¡¢¼¸ºÎÐÎ×´¡¢ÌîÂú¡¢ÎÄ×ֵȵȡ£
½ÓÏÂÀ´£¬ÎÒÃÇ¿ªÊ¼Ò»²½Ò»²½µØ¶ÔPython/PIL µÄÓ°Ïñ´¦Àí³ÌʽÉè¼Æ½øÐÐÌÖÂÛ¡£
2 ת»»Í¼µµ¸ñʽ
ÊÐÃæÉÏÓÐÐí¶àÓ°Ïñ´¦Àí³Ìʽ£¬Ò»°ãÈË×î³£ÓÃËüÃÇÀ´´¦ÀíµÄ¹¤×÷´ó¸Å¾ÍÊÇͼµµ¸ñʽת»»ÁË£»ÕâÊÇÓ°Ïñ´¦ÀíÈíÌå×î»ù±¾µÄ¹¦ÄÜ£¬PIL µ±È»Ò²ÒªÖ§Ô®¡£
¼ÙÉèÎÒÃÇÓÐÒ»¸öJPGµµ°¸£¬Ãû×Ö½Ð×÷ sample01.jpg£¬ÄÇô£¬ÒÔϵijÌʽ»á°ÑÕâ¸öµµ°¸ÔØÈëPython£º
“”>“µ¼ÈëͼÏñ”>“”£¨ÔÚ= Image.open“sample01.jpg”£©
im Õâ¸öÎï¼þÊÇÓÉ Image.open() ·½·¨Ëù²úÉú³öÀ´µÄ Image Îï¼þ¡£ ÎÒÃÇ¿ÉÒÔÓà Image Îï¼þÄÚµÄÊôÐÔÀ´²éѯ¹ØÓڴ˵µ°¸µÄ×ÊѶ£º
“”>“´òÓ¡im.format£¬im.size£¬im.modeµÄJPEG£¨2288£¬1712£©µÄRGB
¸ñʽ×Ö´®·ÅÔÚ format ÊôÐÔÀ³ß´ç·ÅÔÚ size ÊôÐÔÀ¶ø(µ÷É«ÅÌ)ģʽ·ÅÔÚ mode ÊôÐÔÀï¡£&nb
Ïà¹ØÎĵµ£º
ptyhonºËÐıà³ÌµÚÈý°æµÄ×Ôѧ£¬Ö÷Ҫѧϰ±Ê¼Ç·¢Ï£º
µÚÒ»Õ£ºÊ¹ÓÃÈëÃÅ
ÈËÃÇΪʲôʹÓÃPYTHONÓïÑÔ£º
1¡¢Èí¼þÖÊÁ¿£»
2¡¢¿ª·¢ÕßЧÂÊ£»
3¡¢³ÌÐòµÄ¿ÉÒÆÖ²ÐÔ£»
4¡¢×é¼þ¼¯³É£»
5¡¢ÏíÊÜÀÖȤ£»
PYTHONÓïÑÔµÄȱµã£¬¾ÍÊÇËÙ¶ÈÂý¡£
ʹÓÃPYTHON¿ÉÒÔ×öЩʲô£º
1¡¢ÏµÍ³±à³Ì£»
2¡¢Óû§Í¼Ðνӿڣ»
3¡¢INTERNET½Å±¾£»
4¡¢×é¼þ¼¯³É£ ......
Python ×Ö·û´®
×Ö·û´®ÊÇ ×Ö·ûµÄÐòÁÐ ¡£×Ö·û´®»ù±¾ÉϾÍÊÇÒ»×éµ¥´Ê¡£
ÎÒ¼¸ºõ¿ÉÒÔ±£Ö¤ÄãÔÚÿ¸öPython³ÌÐòÖж¼ÒªÓõ½×Ö·û´®£¬ËùÒÔÇëÌرðÁôÐÄÏÂÃæÕⲿ·ÖµÄÄÚÈÝ¡£ÏÂÃæ¸æËßÄãÈçºÎÔÚPythonÖÐʹÓÃ×Ö·û´®¡£
ʹÓõ¥ÒýºÅ£¨'£©
Äã¿ÉÒÔÓõ¥ÒýºÅָʾ×Ö·û´®£¬¾ÍÈçͬ'Quote me on this'ÕâÑù¡£ËùÓеĿհף¬¼´¿Õ¸ñºÍÖƱí·û¶¼ÕÕÔÑù±£Áô¡£ ......
1 #!/usr/bin/python ʹÓÃħ·¨×Ö·ûµ÷ÓÃpython
2
3 from sys import argv µ¼ÈësysÊǵ¼Èëpython½âÊÍÆ÷ºÍËû»·¾³Ïà¹ØµÄ²ÎÊý
4 from os import makedirs,unlink,sep
osÖ÷ÒªÌṩ¶Ôϵͳ·¾¶£¬ÎļþÖØÃüÃûºÍɾ³ýÎļþËùÐèµÄº¯Êý
makedirsÊÇ´´½¨µÝ¹éÎļþ¼ÐµÄº¯Êý¡£±ÈÈç˵ÎÒÃÇÒª´´½¨Ò»¸öеÄĿ¼£¬/python/HTML/crawl,µ«ÊÇÄ ......
Áбí
listÊÇ´¦ÀíÒ»×éÓÐÐòÏîÄ¿µÄÊý¾Ý½á¹¹£¬¼´Äã¿ÉÒÔÔÚÒ»¸öÁбíÖд洢һ¸ö ÐòÁÐ
µÄÏîÄ¿¡£¼ÙÏëÄãÓÐÒ»¸ö¹ºÎïÁÐ±í£¬ÉÏÃæ¼ÇÔØ×ÅÄãÒªÂòµÄ¶«Î÷£¬Äã¾ÍÈÝÒ×Àí½âÁбíÁË¡£Ö»²»¹ýÔÚÄãµÄ¹ºÎï±íÉÏ£¬¿ÉÄÜÿÑù¶«Î÷¶¼¶À×ÔÕ¼ÓÐÒ»ÐУ¬¶øÔÚPythonÖУ¬
ÄãÔÚÿ¸öÏîÄ¿Ö®¼äÓöººÅ·Ö¸î¡£
ÁбíÖеÄÏîÄ¿Ó¦¸Ã°üÀ¨ÔÚ·½À¨ºÅÖУ¬ÕâÑùPython¾ÍÖªµÀÄãÊÇ ......
Ç°¼¸Ìì¿´µ½ÁËÒ»ÐÐÇó1000µÄ½×³ËµÄPython´úÂ룺
print
reduce
(
lambda
x
,
y
:
x
*
y
,
range
(
1
,
1001
))
Ò»ÏÂ×Ó±»python´úÂëµÄ¾«¼ò
Óë½ô´ÕËùÕÛ·þ£¬¹Ê¶Ô´úÂë½øÐÐÁ˼òµ¥µÄ·ÖÎö¡£
reduceÓërange¶¼ÊÇPythonµÄÄÚÖú¯Êý¡£
range£¨1£¬10 ......