python - Using PIL to create thumbnails results in TextEdit Document extension -
using pil, able create thumbnail of picture according computer (running mac os x
), image has extension of textedit document
instead of png
or jpeg
. wondering how can fix result in correct extension.
here code ran:
>>> pil import image >>> import glob, os >>> size = 128, 128 >>> pic = glob.glob("cherngloong1.jpg") >>> im = image.open(pic[0]) >>> im <pil.jpegimageplugin.jpegimagefile image mode=rgb size=2048x1365 @ 0x100a63bd8> >>> im.thumbnail(size, image.antialias) >>> im.save("cherngloong_thumbnail", "png") >>> im.save("cherngloong_thumbnail1", "jpeg")
thumbnail extensions:
this happening because aren't saving filename extension.
most modern operating systems use file extensions determine program should open file.
since called:
>>> im.save("cherngloong_thumbnail", "png") >>> im.save("cherngloong_thumbnail1", "jpeg")
the encoding png/jpg, extension not.
also, why opened textedit, had readme (or other text document) didn't have extension. when opened it, did textedit , files without extension, os x opens files textedit.
to solve problem save this:
im.save("cherngloong_thumbnail.png", "png") im.save("cherngloong_thumbnail1.jpg", "jpeg")
note compatibility, should save lowercase letters, *nix oses deal upper , lower case extensions differently. , treated other image file on computer. read more file extensions on the wikipedia page
Comments
Post a Comment