From fredrik at pythonware.com Wed Jan 2 10:49:11 2008 From: fredrik at pythonware.com (Fredrik Lundh) Date: Wed, 02 Jan 2008 10:49:11 +0100 Subject: [Image-SIG] ImageFont Unicode Decode error In-Reply-To: <200712261640.23347.donn.ingle@gmail.com> References: <200712261640.23347.donn.ingle@gmail.com> Message-ID: Donn wrote: > Trying to open a ttf file with a non-standard character in it (u'\xe5') > causes an error, no matter what I pass to encoding: > self.font = _imagingft.getfont(file, size, index, encoding) > UnicodeEncodeError: 'ascii' codec can't encode character u'\xe5' in position > 66: ordinal not in range(128) > > Is there something I'm doing wrong, or is this a bug? a glitch, at least. the _imagingft driver appears to use Python's default encoding, rather than the filename encoding. should be relatively easy to fix, I think, but in the meantime, you'll have to work around this by making a temporary copy of the file with a made-up name if this happens: try: font = ImageFont.truetype(filename, ...) altname = None except UnicodeEncodeError: # create a suitable alternative name (e.g. using the tempfile # module) altname = ... shutil.copy(filename, altname) # could use linking on Unix font = ImageFont.truetype(altname, ...) ... use the font object ... if altname: os.remove(altname) From donn.ingle at gmail.com Wed Jan 2 11:14:58 2008 From: donn.ingle at gmail.com (Donn) Date: Wed, 2 Jan 2008 12:14:58 +0200 Subject: [Image-SIG] ImageFont Unicode Decode error In-Reply-To: References: <200712261640.23347.donn.ingle@gmail.com> Message-ID: <200801021214.58612.donn.ingle@gmail.com> > should be relatively easy to fix, I think, but in the meantime, you'll > have to work around this by making a temporary copy of the file with a > made-up name if this happens: Thanks for the feedback and the idea. \d From fredrik at pythonware.com Wed Jan 2 22:22:41 2008 From: fredrik at pythonware.com (Fredrik Lundh) Date: Wed, 02 Jan 2008 22:22:41 +0100 Subject: [Image-SIG] ImageFont Unicode Decode error In-Reply-To: References: <200712261640.23347.donn.ingle@gmail.com> Message-ID: I wrote: > a glitch, at least. the _imagingft driver appears to use Python's > default encoding, rather than the filename encoding. > > should be relatively easy to fix, I think For the record, here's a (preliminary) patch: $ svn diff _imagingft.c Index: _imagingft.c =================================================================== --- _imagingft.c (revision 3349) +++ _imagingft.c (working copy) @@ -117,9 +118,17 @@ static char* kwlist[] = { "filename", "size", "index", "encoding", NULL }; + +#if defined(HAVE_UNICODE) + if (!PyArg_ParseTupleAndKeywords(args, kw, "eti|is", kwlist, + Py_FileSystemDefaultEncoding, &filename, + &size, &index, &encoding)) + return NULL; +#else if (!PyArg_ParseTupleAndKeywords(args, kw, "si|is", kwlist, &filename, &size, &index, &encoding)) return NULL; +#endif if (!library && FT_Init_FreeType(&library)) { PyErr_SetString( From adam at volition-inc.com Wed Jan 2 22:52:54 2008 From: adam at volition-inc.com (Adam Pletcher) Date: Wed, 2 Jan 2008 15:52:54 -0600 Subject: [Image-SIG] buffer overrun loading some TGAs Message-ID: <893A44FF792E904A97B7515CE341914601F9953C@volimxs01.thqinc.com> Hello. I searched the archives for this but came up empty. I'm getting a "image buffer overrun error", when doing the first operation on certain image files. Specifically in \PIL\ImageFile.py, line 207, PIL 1.1.6. It appears limited to certain RGBA Targa images. The odd part is, if the operation is immediately run again it works fine with no errors. For example: >>> img = Image.open(r'D:\temp\hud_sheet_04.tga') >>> img2 = img.convert('RGB') Traceback (most recent call last): File "", line 1, in img2 = img.convert('RGB') File "C:\Python25\lib\site-packages\PIL\Image.py", line 653, in convert self.load() File "C:\Python25\lib\site-packages\PIL\ImageFile.py", line 207, in load raise IOError(error + " when reading image file") IOError: image buffer overrun error when reading image file >>> img2 = img.convert('RGB') >>> Am I missing something? Is there something non-standard about these image files? I'm guessing so, but I can't nail it down. I've successfully loaded them in in various programs with no issues. It appears I can get PIL to load them by re-saving them in certain programs, even though no other apps give me load errors. I posted one culprit image file in case someone is able to test/confirm for me: http://www.adamsarcade.com/misc/hud_sheet_04.tga I can put a second operation attempt inside a try/except, but I'm preparing this script for a talk I'm giving and I'd like to avoid that kind of hackery if possible. Any suggestions appreciated. -- Adam Pletcher Technical Art Director Volition/THQ From fredrik at pythonware.com Wed Jan 2 23:29:55 2008 From: fredrik at pythonware.com (Fredrik Lundh) Date: Wed, 02 Jan 2008 23:29:55 +0100 Subject: [Image-SIG] buffer overrun loading some TGAs In-Reply-To: <893A44FF792E904A97B7515CE341914601F9953C@volimxs01.thqinc.com> References: <893A44FF792E904A97B7515CE341914601F9953C@volimxs01.thqinc.com> Message-ID: Adam Pletcher wrote: > Am I missing something? Is there something non-standard about these > image files? I'm guessing so, but I can't nail it down. I've > successfully loaded them in in various programs with no issues. It > appears I can get PIL to load them by re-saving them in certain > programs, even though no other apps give me load errors. > > I posted one culprit image file in case someone is able to test/confirm > for me: > http://www.adamsarcade.com/misc/hud_sheet_04.tga I can repeat this with the development version. It's an RLE-compressed targa file, so you've probably hit some edge case that PIL's decoder isn't handling properly. > It appears limited to certain RGBA Targa images. The odd part is, if > the operation is immediately run again it works fine with no errors. Have you checked that the resulting image contains the right data? From adam at volition-inc.com Wed Jan 2 23:45:56 2008 From: adam at volition-inc.com (Adam Pletcher) Date: Wed, 2 Jan 2008 16:45:56 -0600 Subject: [Image-SIG] buffer overrun loading some TGAs In-Reply-To: References: <893A44FF792E904A97B7515CE341914601F9953C@volimxs01.thqinc.com> Message-ID: <893A44FF792E904A97B7515CE341914601F99556@volimxs01.thqinc.com> > I can repeat this with the development version. It's an RLE-compressed > targa file, so you've probably hit some edge case that PIL's decoder > isn't handling properly. Ah, sweet. > Have you checked that the resulting image contains the right data? It doesn't, turns out. It's the right size but the pixels are garbage. - Adam From fredrik at pythonware.com Thu Jan 3 00:20:14 2008 From: fredrik at pythonware.com (Fredrik Lundh) Date: Thu, 03 Jan 2008 00:20:14 +0100 Subject: [Image-SIG] buffer overrun loading some TGAs In-Reply-To: <893A44FF792E904A97B7515CE341914601F99556@volimxs01.thqinc.com> References: <893A44FF792E904A97B7515CE341914601F9953C@volimxs01.thqinc.com> <893A44FF792E904A97B7515CE341914601F99556@volimxs01.thqinc.com> Message-ID: Adam Pletcher wrote: >> I can repeat this with the development version. It's an >> RLE-compressed targa file, so you've probably hit some edge >> case that PIL's decoder isn't handling properly. > > Ah, sweet. looks as if PIL's decode messes up for runs that spans multiple rows; this is obviously not very common (the decoder was written in 1997, and I'm pretty sure this hasn't been reported before), but appears to be perfectly legal according the Targa documentation. time to dive into some ancient C code, it seems. From carl at personnelware.com Thu Jan 3 00:32:05 2008 From: carl at personnelware.com (Carl Karsten) Date: Wed, 02 Jan 2008 17:32:05 -0600 Subject: [Image-SIG] less disk IO Message-ID: <477C1EF5.9040903@personnelware.com> I am trying to convert a pdf (data in string, not disk file) to a png. This will be run in a django view on a server (PyCon's even) so it would be good if it didn't hit the disk as much. Shouldn't I be able to use .tostring if I can use .save? I gave up trying to convert the pdf. The things that might have actually worked were not stable enough to be put onto the production server. If you think you know a way, please code it first. If it takes you longer than 10 min, or more than 100 words to describe the setup, it probably isn't going to get used :) Also, I have been told about 10 times now that it should be easy. I agree. so far no one has proved it. Thanks, Carl K def sample(ds): """ make a sample badge""" # this is some clunky code. # it bounces the data off the disk more times than I care to count # It would be nice if it was all done in memory, # but I couldn't figure out how. import PIL, Image import tempfile ds['attendeeID']='SAMPLE' pdf = mkpdf(ds) tempDir = tempfile.mkdtemp( prefix = "badgePreview_" ) pdfname = path.join( tempDir, 'badge.pdf' ) imgname = path.join( tempDir, 'badge.png' ) open(pdfname,'wb').write(pdf) # convert pdf to some image format (uses ext to determine type) system('convert %s %s' % (pdfname, imgname)) # crop the badge (pdf may be 8x11 page) Image.open(imgname).crop([0,0,300,235]).save(imgname) # I am sure there is a way to get the image out of im # so that I don't have to send it back to the disk. # im=Image.open(imgname) # im=im.crop([0,0,300,235]) # img=im.tostring('raw') # The image x cannot be displayed, because it contains errors. # img=im.tostring('PNG') # encoder PNG not available # img=im.tostring('png') # encoder png not available img = open(imgname).read() remove(pdfname) remove(imgname) rmdir(tempDir) return img From douglas at paradise.net.nz Thu Jan 3 04:17:36 2008 From: douglas at paradise.net.nz (Douglas Bagnall) Date: Thu, 03 Jan 2008 16:17:36 +1300 Subject: [Image-SIG] less disk IO In-Reply-To: <477C1EF5.9040903@personnelware.com> References: <477C1EF5.9040903@personnelware.com> Message-ID: <477C53D0.3@paradise.net.nz> Carl Karsten wrote: > I am trying to convert a pdf (data in string, not disk file) to a png. This > will be run in a django view on a server (PyCon's even) so it would be good if > it didn't hit the disk as much. Shouldn't I be able to use .tostring if I can > use .save? use cStringIO. http://docs.python.org/lib/module-StringIO.html It might not make much difference, because your OS should be caching the file in memory anyway, and letting you read it back before it is actually written to disk. If you are sure it is a disk problem, you could set it up to write to a ram file system (e.g. tmpfs on linux), which would help the PDF conversion too. Otherwise you could see if it possible to communicate with the convert script using pipes, rather than system(). That will cut out a few reads and writes. Douglas From carl at personnelware.com Thu Jan 3 04:43:58 2008 From: carl at personnelware.com (Carl Karsten) Date: Wed, 02 Jan 2008 21:43:58 -0600 Subject: [Image-SIG] less disk IO In-Reply-To: <477C53D0.3@paradise.net.nz> References: <477C1EF5.9040903@personnelware.com> <477C53D0.3@paradise.net.nz> Message-ID: <477C59FE.60206@personnelware.com> Douglas Bagnall wrote: > Carl Karsten wrote: > >> I am trying to convert a pdf (data in string, not disk file) to a png. This >> will be run in a django view on a server (PyCon's even) so it would be good if >> it didn't hit the disk as much. Shouldn't I be able to use .tostring if I can >> use .save? > > use cStringIO. I saw some mention of that in the IM docs. any idea why .tostring doesn't work? > > It might not make much difference, because your OS should be caching the > file in memory anyway, and letting you read it back before it is > actually written to disk. busy server, so if I can easily make it better... Also, keeping everything in memory means nothing to clean up when things crash. which happens often enough, that if I can make it better... > > If you are sure it is a disk problem, you could set it up to write to a > ram file system (e.g. tmpfs on linux), which would help the PDF > conversion too. well, not sure. just a feeling and some comments from an admin. make it better... :) > > Otherwise you could see if it possible to communicate with the convert > script using pipes, rather than system(). That will cut out a few reads > and writes. I hear pipes aren't thread safe, and/or can deadlock the web server. no time to figure that out, so i am just avoiding it. also, I just discovered http://packages.ubuntu.com/hardy/python/python-pythonmagick but I can't find docs. any suggestions? (not sure if I will be able to install this package on the server it needs to be on, so I am going to try to spend less than 30 min on it ... might happen ;) Carl K > > > Douglas > _______________________________________________ > Image-SIG maillist - Image-SIG at python.org > http://mail.python.org/mailman/listinfo/image-sig > > From fredrik at pythonware.com Thu Jan 3 11:22:14 2008 From: fredrik at pythonware.com (Fredrik Lundh) Date: Thu, 03 Jan 2008 11:22:14 +0100 Subject: [Image-SIG] less disk IO In-Reply-To: <477C59FE.60206@personnelware.com> References: <477C1EF5.9040903@personnelware.com> <477C53D0.3@paradise.net.nz> <477C59FE.60206@personnelware.com> Message-ID: Carl Karsten wrote: > I saw some mention of that in the IM docs. any idea why .tostring doesn't work? the tostring method returns pixel data as a packed array, not data in an image interchange file format. (tostring/fromstring is a common data interchange protocol for array- style objects in Python; see e.g. the array module and numerical python). From carl at personnelware.com Thu Jan 3 15:37:24 2008 From: carl at personnelware.com (Carl Karsten) Date: Thu, 03 Jan 2008 08:37:24 -0600 Subject: [Image-SIG] less disk IO In-Reply-To: References: <477C1EF5.9040903@personnelware.com> <477C53D0.3@paradise.net.nz> <477C59FE.60206@personnelware.com> Message-ID: <477CF324.7020805@personnelware.com> Fredrik Lundh wrote: > Carl Karsten wrote: > >> I saw some mention of that in the IM docs. any idea why .tostring doesn't work? > > the tostring method returns pixel data as a packed array, not data in an > image interchange file format. > > (tostring/fromstring is a common data interchange protocol for array- > style objects in Python; see e.g. the array module and numerical python). > Ah! Thank you. now I don't feel so bad using StringIO. I thought I just couldn't figure it out. Carl K From angelol at easyconnect.fr Fri Jan 4 03:44:50 2008 From: angelol at easyconnect.fr (angelo) Date: Fri, 04 Jan 2008 03:44:50 +0100 Subject: [Image-SIG] What's wrong for me ? Message-ID: <1199414690.5194.5.camel@kubuntu1> I'm searching ton send a message to the list with my new user subscription (it's just a test message), but: Your mail to 'Image-SIG' with the subject It's just a connect test to the list Is being held until the list moderator can review it for approval. The reason it is being held: Message has a suspicious header Either the message will get posted to the list, or you will receive notification of the moderator's decision. If you would like to cancel this posting, please visit the following URL: ... a+ -- Venez faire un tour ici : http://ekd.tolosano.info http://monsitt.irruption.net http://irruption.net/progdudim From fredrik at pythonware.com Fri Jan 4 14:54:45 2008 From: fredrik at pythonware.com (Fredrik Lundh) Date: Fri, 04 Jan 2008 14:54:45 +0100 Subject: [Image-SIG] What's wrong for me ? In-Reply-To: <1199414690.5194.5.camel@kubuntu1> References: <1199414690.5194.5.camel@kubuntu1> Message-ID: angelo wrote: > I'm searching ton send a message to the list with my new user > subscription (it's just a test message), but: Please don't send test messages to the list; if you have something to ask, just post the question. If you don't get a reply, check the archives (mail.python.org) after a while. If the message is there, wait at least a few days before asking again. > Your mail to 'Image-SIG' with the subject > > It's just a connect test to the list > > Is being held until the list moderator can review it for approval. > > The reason it is being held: > > Message has a suspicious header > > Either the message will get posted to the list, or you will receive > notification of the moderator's decision. If you would like to cancel > this posting, please visit the following URL: I suspect that the mailing list is set up to catch things that look like administrative messages, test messages, and other "noise" messages. The moderation queue is processed a few times per week. From sedrik at gmail.com Wed Jan 9 00:42:54 2008 From: sedrik at gmail.com (Andy McCurdy) Date: Tue, 8 Jan 2008 15:42:54 -0800 Subject: [Image-SIG] Poor Image Quality When Resizing a GIF Message-ID: <55bd76f30801081542q625395f6m77ad0dda30d11dd7@mail.gmail.com> Hi all, Just started using PIL. I'm attempting to resize a .gif image to a smaller size, keeping the height/width proportional. The resize works, but the resulting image is very grainy. Resizing the same image with ImageMagick's convert utility produced a far better quality image. I'd rather use PIL if possible since it has a much better API. The below code works fine with JPG files. Am I missing something? from PIL import Image # original_content is a string of bytes representing the image. # the image is not stored locally on disk, so it's fetched from the storage service as a string # and loaded up using a StringIO buffer # Have also tried loading the same .gif from a local disk directly with Image.open('filename.gif'), but image after resize looked grainy as well io = StringIO(original_content) pil_image = Image.open (io) # docs suggest that the default mode, 'P', won't use the ANTIALIAS filter, so switch to RGB pil_image = pil_image.convert('RGB') # ... stuff happens here to figure out what the new width and height should be # tuple representing the new size new_size = (new_width, new_height) # the actual resize... pil_image = pil_image.resize(new_size, Image.ANTIALIAS) # save the new image back out to a StringIO buffer -- has to be sent back to the storage service io = StringIO() format = 'GIF' # hardcoded in this example pil_image.save(io, format) Thanks for any help possible. From fredrik at pythonware.com Wed Jan 9 09:28:41 2008 From: fredrik at pythonware.com (Fredrik Lundh) Date: Wed, 09 Jan 2008 09:28:41 +0100 Subject: [Image-SIG] Poor Image Quality When Resizing a GIF In-Reply-To: <55bd76f30801081542q625395f6m77ad0dda30d11dd7@mail.gmail.com> References: <55bd76f30801081542q625395f6m77ad0dda30d11dd7@mail.gmail.com> Message-ID: Andy McCurdy wrote: > Just started using PIL. I'm attempting to resize a .gif image to a > smaller size, keeping the height/width proportional. The resize > works, but the resulting image is very grainy. try converting the image to "RGB" first, and use resize(ANTIALIAS) on the RGB image before converting it back to P. (if you resize a "P" image as is, you can only use the NEAREST resampling method. this works reasonably well for certain kinds of "graphics", but less so for images that are dithered. for some kinds of images, smoothing the RGB image before resizing it might also help.) From spaceoutlet at gmail.com Wed Jan 9 13:58:50 2008 From: spaceoutlet at gmail.com (Alex K) Date: Wed, 9 Jan 2008 13:58:50 +0100 Subject: [Image-SIG] rounded corners Message-ID: Hello, Would anyone know how to generate thumbnails with rounded corners using PIL? I'm also considering imagemagick if PIL turns out not to be appropriate for the task. Thank you so much, Alex From spe.stani.be at gmail.com Wed Jan 9 14:43:02 2008 From: spe.stani.be at gmail.com (Stani) Date: Wed, 09 Jan 2008 14:43:02 +0100 Subject: [Image-SIG] rounded corners In-Reply-To: References: Message-ID: <4784CF66.8060203@gmail.com> In PIL this is easy. The following code preferably uses cache (just a simple python dictionary) to avoid the overhead of generating the same transparency masks. So typical use would be: cache = {} for image in images: thumbnail = image_round(image.thumbnail(size, filter), cache, radius) Here is the code for rounded corners: # Rounded corners # (c) 2008 www.stani.be # License: same as PIL CROSS = _t('Cross') ROUNDED = _t('Rounded') SQUARE = _t('Square') CORNERS = [ROUNDED,SQUARE,CROSS] CORNER_ID = 'rounded_corner_r%d_f%d' CROSS_POS = (CROSS,CROSS,CROSS,CROSS) ROUNDED_POS = (ROUNDED,ROUNDED,ROUNDED,ROUNDED) ROUNDED_RECTANGLE_ID = 'rounded_rectangle_r%d_f%d_s%s_p%s' def round_image(image,cache={},radius=100,fill=255,pos=ROUNDED_POS, back_colour='#FFFFFF'): if image.mode != 'RGBA': image = image.convert('RGBA') mask = create_rounded_rectangle(image.size,cache,radius,fill,pos) image.paste(Image.new('RGB',image.size,back_colour),(0,0), ImageChops.invert(mask)) image.putalpha(mask) return image def create_corner(radius=100,fill=255,factor=2): corner = Image.new('L',(factor*radius,factor*radius),0) draw = ImageDraw.Draw(corner) draw.pieslice((0,0,2*factor*radius,2*factor*radius),180,270,fill=fill) corner = corner.resize((radius,radius),Image.ANTIALIAS) return corner def create_rounded_rectangle(size=(600,400),cache={},radius=100,fill=255, pos=ROUNDED_POS): #rounded_rectangle im_x, im_y = size rounded_rectangle_id = ROUNDED_RECTANGLE_ID%(radius,fill,size,pos) if cache.has_key(rounded_rectangle_id): return cache[rounded_rectangle_id] else: #cross cross_id = ROUNDED_RECTANGLE_ID%(radius,fill,size,CROSS_POS) if cache.has_key(cross_id): cross = cache[cross_id] else: cross = cache[cross_id] = Image.new('L',size,0) draw = ImageDraw.Draw(cross) draw.rectangle((radius,0,im_x-radius,im_y),fill=fill) draw.rectangle((0,radius,im_x,im_y-radius),fill=fill) if pos==CROSS_POS: return cross #corner corner_id = CORNER_ID%(radius,fill) if cache.has_key(corner_id): corner = cache[corner_id] else: corner = cache[corner_id] = create_corner(radius,fill) #rounded rectangle rectangle = Image.new('L',(radius,radius),255) rounded_rectangle = cross.copy() for index, angle in enumerate(pos): if angle == CROSS: break if angle == ROUNDED: element = corner else: element = rectangle if index%2: x = im_x-radius element = element.transpose(Image.FLIP_LEFT_RIGHT) else: x = 0 if index < 2: y = 0 else: y = im_y-radius element = element.transpose(Image.FLIP_TOP_BOTTOM) rounded_rectangle.paste(element,(x,y)) cache[rounded_rectangle_id] = rounded_rectangle return rounded_rectangle Alex K schreef: > Hello, > > Would anyone know how to generate thumbnails with rounded corners > using PIL? I'm also considering imagemagick if PIL turns out not to be > appropriate for the task. > > Thank you so much, > > Alex > _______________________________________________ > Image-SIG maillist - Image-SIG at python.org > http://mail.python.org/mailman/listinfo/image-sig > From spe.stani.be at gmail.com Wed Jan 9 14:45:31 2008 From: spe.stani.be at gmail.com (Stani) Date: Wed, 09 Jan 2008 14:45:31 +0100 Subject: [Image-SIG] rounded corners In-Reply-To: <4784CF66.8060203@gmail.com> References: <4784CF66.8060203@gmail.com> Message-ID: <4784CFFB.5080904@gmail.com> I forgot to take of the _t function, so the first lines should be: CROSS = 'Cross' ROUNDED = 'Rounded' SQUARE = 'Square' Stani schreef: > In PIL this is easy. > > The following code preferably uses cache (just a simple python > dictionary) to avoid the overhead of generating the same transparency > masks. So typical use would be: > > cache = {} > for image in images: > thumbnail = image_round(image.thumbnail(size, filter), cache, radius) > > Here is the code for rounded corners: > > # Rounded corners > # (c) 2008 www.stani.be > # License: same as PIL > > CROSS = _t('Cross') > ROUNDED = _t('Rounded') > SQUARE = _t('Square') > > CORNERS = [ROUNDED,SQUARE,CROSS] > CORNER_ID = 'rounded_corner_r%d_f%d' > CROSS_POS = (CROSS,CROSS,CROSS,CROSS) > ROUNDED_POS = (ROUNDED,ROUNDED,ROUNDED,ROUNDED) > ROUNDED_RECTANGLE_ID = 'rounded_rectangle_r%d_f%d_s%s_p%s' > > def round_image(image,cache={},radius=100,fill=255,pos=ROUNDED_POS, > back_colour='#FFFFFF'): > if image.mode != 'RGBA': > image = image.convert('RGBA') > mask = create_rounded_rectangle(image.size,cache,radius,fill,pos) > image.paste(Image.new('RGB',image.size,back_colour),(0,0), > ImageChops.invert(mask)) > image.putalpha(mask) > return image > > def create_corner(radius=100,fill=255,factor=2): > corner = Image.new('L',(factor*radius,factor*radius),0) > draw = ImageDraw.Draw(corner) > draw.pieslice((0,0,2*factor*radius,2*factor*radius),180,270,fill=fill) > corner = corner.resize((radius,radius),Image.ANTIALIAS) > return corner > > def create_rounded_rectangle(size=(600,400),cache={},radius=100,fill=255, > pos=ROUNDED_POS): > #rounded_rectangle > im_x, im_y = size > rounded_rectangle_id = ROUNDED_RECTANGLE_ID%(radius,fill,size,pos) > if cache.has_key(rounded_rectangle_id): > return cache[rounded_rectangle_id] > else: > #cross > cross_id = ROUNDED_RECTANGLE_ID%(radius,fill,size,CROSS_POS) > if cache.has_key(cross_id): > cross = cache[cross_id] > else: > cross = cache[cross_id] = Image.new('L',size,0) > draw = ImageDraw.Draw(cross) > draw.rectangle((radius,0,im_x-radius,im_y),fill=fill) > draw.rectangle((0,radius,im_x,im_y-radius),fill=fill) > if pos==CROSS_POS: > return cross > #corner > corner_id = CORNER_ID%(radius,fill) > if cache.has_key(corner_id): > corner = cache[corner_id] > else: > corner = cache[corner_id] = create_corner(radius,fill) > #rounded rectangle > rectangle = Image.new('L',(radius,radius),255) > rounded_rectangle = cross.copy() > for index, angle in enumerate(pos): > if angle == CROSS: > break > if angle == ROUNDED: > element = corner > else: > element = rectangle > if index%2: > x = im_x-radius > element = element.transpose(Image.FLIP_LEFT_RIGHT) > else: > x = 0 > if index < 2: > y = 0 > else: > y = im_y-radius > element = element.transpose(Image.FLIP_TOP_BOTTOM) > rounded_rectangle.paste(element,(x,y)) > cache[rounded_rectangle_id] = rounded_rectangle > return rounded_rectangle > > > Alex K schreef: >> Hello, >> >> Would anyone know how to generate thumbnails with rounded corners >> using PIL? I'm also considering imagemagick if PIL turns out not to be >> appropriate for the task. >> >> Thank you so much, >> >> Alex >> _______________________________________________ >> Image-SIG maillist - Image-SIG at python.org >> http://mail.python.org/mailman/listinfo/image-sig >> > From sedrik at gmail.com Tue Jan 8 10:55:20 2008 From: sedrik at gmail.com (Andy McCurdy) Date: Tue, 8 Jan 2008 01:55:20 -0800 Subject: [Image-SIG] Poor Image Quality When Resizing Message-ID: <55bd76f30801080155m637a62bdic46dc1c21fb15c84@mail.gmail.com> Hi all, Just started using PIL. I'm attempting to resize a .gif image to a smaller size, keeping the height/width proportional. The resize works, but the resulting image is very grainy. Resizing the same image with ImageMagick's convert utility produced a far better quality image. I'd rather use PIL if possible since it has a much better API. Am I missing something? from PIL import Image # original_content is a string of bytes representing the image. # the image is not stored locally on disk, so it's fetched from the storage service as a string # and loaded up using a StringIO buffer # Have also tried loading the same .gif from a local disk directly with Image.open('filename.gif'), but image after resize looked grainy as well io = StringIO(original_content) pil_image = Image.open(io) # docs suggest that the default mode, 'P', won't use the ANTIALIAS filter, so switch to RGB pil_image = pil_image.convert('RGB') # ... stuff happens here to figure out what the new width and height should be # tuple representing the new size new_size = (new_width, new_height) # the actual resize... pil_image = pil_image.resize(new_size, Image.ANTIALIAS) # save the new image back out to a StringIO buffer -- has to be sent back to the storage service io = StringIO() format = 'GIF' # hardcoded in this example pil_image.save(io, format) Thanks for any help possible. -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/image-sig/attachments/20080108/05ebd312/attachment.htm From tiptip.barish at gmail.com Tue Jan 8 20:54:13 2008 From: tiptip.barish at gmail.com (Varsha purohit) Date: Tue, 8 Jan 2008 11:54:13 -0800 Subject: [Image-SIG] Zooming any image Message-ID: <9636adca0801081154u2af4da5al5479ad6c055df195@mail.gmail.com> Hello All, In my program i have a gui where i am showing an image on the panel. I want to implement zoom in and zoom out functions using wxpython and PIL. I am tryin to find in PIL if there is any functionality like that. Any help is appreciated. - Varsha -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/image-sig/attachments/20080108/abc3a7d1/attachment.htm From fredrik at pythonware.com Wed Jan 9 16:16:00 2008 From: fredrik at pythonware.com (Fredrik Lundh) Date: Wed, 09 Jan 2008 16:16:00 +0100 Subject: [Image-SIG] Zooming any image In-Reply-To: <9636adca0801081154u2af4da5al5479ad6c055df195@mail.gmail.com> References: <9636adca0801081154u2af4da5al5479ad6c055df195@mail.gmail.com> Message-ID: Varsha purohit wrote: > In my program i have a gui where i am showing an image on the > panel. I want to implement zoom in and zoom out functions using wxpython > and PIL. I am tryin to find in PIL if there is any functionality like that. the transpose(EXTENT) method is often used for this: http://effbot.org/tag/PIL.Image.Image.transform just pass in the size of the viewport and the area you want to display, given as a bounding box. From andy at andymccurdy.com Wed Jan 9 17:32:47 2008 From: andy at andymccurdy.com (Andy McCurdy) Date: Wed, 9 Jan 2008 08:32:47 -0800 Subject: [Image-SIG] Poor Image Quality When Resizing a GIF In-Reply-To: References: <55bd76f30801081542q625395f6m77ad0dda30d11dd7@mail.gmail.com> Message-ID: <55bd76f30801090832n768f08daoba298e20d7d7a81@mail.gmail.com> Fredrik, thanks for the reply. I am in fact converting to "RGB" first... at least I think so. Here's the code I'm using that produces bad results: from PIL import Image # io is a file handle pil_image = Image.open(io) # convert to rgb pil_image = pil_image.convert('RGB') # new_width/new_height are calculated to retain the # current height/width proportions new_size = (new_width, new_height) #resize the image pil_image = pil_image.resize(new_size, Image.ANTIALIAS) # save the image back to disk pil_image.save(io, 'GIF') On Jan 9, 2008 12:28 AM, Fredrik Lundh wrote: > Andy McCurdy wrote: > > > Just started using PIL. I'm attempting to resize a .gif image to a > > smaller size, keeping the height/width proportional. The resize > > works, but the resulting image is very grainy. > > try converting the image to "RGB" first, and use resize(ANTIALIAS) on > the RGB image before converting it back to P. > > (if you resize a "P" image as is, you can only use the NEAREST > resampling method. this works reasonably well for certain kinds of > "graphics", but less so for images that are dithered. for some kinds of > images, smoothing the RGB image before resizing it might also help.) > > > > _______________________________________________ > Image-SIG maillist - Image-SIG at python.org > http://mail.python.org/mailman/listinfo/image-sig > From fredrik at pythonware.com Wed Jan 9 22:13:19 2008 From: fredrik at pythonware.com (Fredrik Lundh) Date: Wed, 09 Jan 2008 22:13:19 +0100 Subject: [Image-SIG] Poor Image Quality When Resizing a GIF In-Reply-To: <55bd76f30801090832n768f08daoba298e20d7d7a81@mail.gmail.com> References: <55bd76f30801081542q625395f6m77ad0dda30d11dd7@mail.gmail.com> <55bd76f30801090832n768f08daoba298e20d7d7a81@mail.gmail.com> Message-ID: Andy McCurdy wrote: > Fredrik, thanks for the reply. I am in fact converting to "RGB" > first... at least I think so. Here's the code I'm using that produces > bad results: > > from PIL import Image > > # io is a file handle > pil_image = Image.open(io) > > # convert to rgb > pil_image = pil_image.convert('RGB') > > # new_width/new_height are calculated to retain the > # current height/width proportions > new_size = (new_width, new_height) > > #resize the image > pil_image = pil_image.resize(new_size, Image.ANTIALIAS) > > # save the image back to disk > pil_image.save(io, 'GIF') is the grain you're talking about perhaps floyd-steinberg dithering? do your images look better if you insert pil_image = pil_image.convert("P", dither=Image.NONE) before you save the image? From andy at andymccurdy.com Wed Jan 9 22:59:41 2008 From: andy at andymccurdy.com (Andy McCurdy) Date: Wed, 9 Jan 2008 13:59:41 -0800 Subject: [Image-SIG] Poor Image Quality When Resizing a GIF In-Reply-To: References: <55bd76f30801081542q625395f6m77ad0dda30d11dd7@mail.gmail.com> <55bd76f30801090832n768f08daoba298e20d7d7a81@mail.gmail.com> Message-ID: <55bd76f30801091359q109b0c0bh2a61b14f13f4226c@mail.gmail.com> Your suggestion didn't seem to fix the problem. It will probably be helpful for you to take a look at what I'm seeing. Here's the original .gif file I'm testing with: http://www.andymccurdy.com/original.gif Here's the resized gif with the original code I pasted. You'll see a bunch of 'dots' throughout the image: http://www.andymccurdy.com/resized_1.gif Here's the image resized again with your suggestion of converting to "P" mode and setting the dithering prior to saving: http://www.andymccurdy.com/resized_2.gif You'll see both of the resized images are pretty poor quality. On Jan 9, 2008 1:13 PM, Fredrik Lundh wrote: > Andy McCurdy wrote: > > > Fredrik, thanks for the reply. I am in fact converting to "RGB" > > first... at least I think so. Here's the code I'm using that produces > > bad results: > > > > from PIL import Image > > > > # io is a file handle > > pil_image = Image.open(io) > > > > # convert to rgb > > pil_image = pil_image.convert('RGB') > > > > # new_width/new_height are calculated to retain the > > # current height/width proportions > > new_size = (new_width, new_height) > > > > #resize the image > > pil_image = pil_image.resize(new_size, Image.ANTIALIAS) > > > > # save the image back to disk > > pil_image.save(io, 'GIF') > > is the grain you're talking about perhaps floyd-steinberg dithering? do > your images look better if you insert > > pil_image = pil_image.convert("P", dither=Image.NONE) > > before you save the image? > > > > > _______________________________________________ > Image-SIG maillist - Image-SIG at python.org > http://mail.python.org/mailman/listinfo/image-sig > From douglas at paradise.net.nz Wed Jan 9 23:57:12 2008 From: douglas at paradise.net.nz (douglas bagnall) Date: Thu, 10 Jan 2008 11:57:12 +1300 Subject: [Image-SIG] Poor Image Quality When Resizing a GIF In-Reply-To: <55bd76f30801091359q109b0c0bh2a61b14f13f4226c@mail.gmail.com> References: <55bd76f30801081542q625395f6m77ad0dda30d11dd7@mail.gmail.com> <55bd76f30801090832n768f08daoba298e20d7d7a81@mail.gmail.com> <55bd76f30801091359q109b0c0bh2a61b14f13f4226c@mail.gmail.com> Message-ID: hi Andy > Here's the resized gif with the original code I pasted. You'll see a > bunch of 'dots' throughout the image: > http://www.andymccurdy.com/resized_1.gif PIL uses the so-called "web palette" by default. Your image uses #fdfdfd for white, but the web palette uses #ffffff. So it dithers to approximate #fdfdfd. You probably really want the background to be pure #ffffff white, because printers etc will also dither, but the more immediate problem is the web palette. Try this: pil_image = pil_image.convert("P", palette=Image.ADAPTIVE) or pil_image = pil_image.convert("P", dither=Image.NONE, palette=Image.ADAPTIVE) These options are not well documented, but you can find them in the PIL/Image.py source. douglas From andy at andymccurdy.com Thu Jan 10 00:08:50 2008 From: andy at andymccurdy.com (Andy McCurdy) Date: Wed, 9 Jan 2008 15:08:50 -0800 Subject: [Image-SIG] Poor Image Quality When Resizing a GIF In-Reply-To: References: <55bd76f30801081542q625395f6m77ad0dda30d11dd7@mail.gmail.com> <55bd76f30801090832n768f08daoba298e20d7d7a81@mail.gmail.com> <55bd76f30801091359q109b0c0bh2a61b14f13f4226c@mail.gmail.com> Message-ID: <55bd76f30801091508h20c0a0a6n83be9ffe312487b2@mail.gmail.com> Hey Douglas, I interpreted your response as a setting to change to make this specific image resize better. I'm using PIL to resize images that users upload to my website. Since I don't have control over the media, I need generic settings that will be good for all users. What settings would you suggest to be best for all images, not just the example I provided? On Jan 9, 2008 2:57 PM, douglas bagnall wrote: > hi Andy > > > Here's the resized gif with the original code I pasted. You'll see a > > bunch of 'dots' throughout the image: > > http://www.andymccurdy.com/resized_1.gif > > PIL uses the so-called "web palette" by default. Your image uses > #fdfdfd for white, but the web palette uses #ffffff. So it dithers to > approximate #fdfdfd. You probably really want the background to be > pure #ffffff white, because printers etc will also dither, but the > more immediate problem is the web palette. Try this: > > pil_image = pil_image.convert("P", palette=Image.ADAPTIVE) > > or > > pil_image = pil_image.convert("P", dither=Image.NONE, palette=Image.ADAPTIVE) > > These options are not well documented, but you can find them in the > PIL/Image.py source. > > douglas > > _______________________________________________ > Image-SIG maillist - Image-SIG at python.org > http://mail.python.org/mailman/listinfo/image-sig > From douglas at paradise.net.nz Thu Jan 10 00:34:07 2008 From: douglas at paradise.net.nz (douglas bagnall) Date: Thu, 10 Jan 2008 12:34:07 +1300 Subject: [Image-SIG] Poor Image Quality When Resizing a GIF In-Reply-To: <55bd76f30801091508h20c0a0a6n83be9ffe312487b2@mail.gmail.com> References: <55bd76f30801081542q625395f6m77ad0dda30d11dd7@mail.gmail.com> <55bd76f30801090832n768f08daoba298e20d7d7a81@mail.gmail.com> <55bd76f30801091359q109b0c0bh2a61b14f13f4226c@mail.gmail.com> <55bd76f30801091508h20c0a0a6n83be9ffe312487b2@mail.gmail.com> Message-ID: Andy McCurdy wrote: > I interpreted your response as a setting to change to make this > specific image resize better. I'm using PIL to resize images that > users upload to my website. Since I don't have control over the > media, I need generic settings that will be good for all users. What > settings would you suggest to be best for all images, not just the > example I provided? Using palette=Image.ADAPTIVE will be better for all images unless the images are already in the web palette, or the viewers are from 1995 and have 256 colour displays. Both of these are unlikely, and in any case the adaptive system will work well enough for them. It will be slower though. douglas From andy at andymccurdy.com Thu Jan 10 00:45:16 2008 From: andy at andymccurdy.com (Andy McCurdy) Date: Wed, 9 Jan 2008 15:45:16 -0800 Subject: [Image-SIG] Poor Image Quality When Resizing a GIF In-Reply-To: References: <55bd76f30801081542q625395f6m77ad0dda30d11dd7@mail.gmail.com> <55bd76f30801090832n768f08daoba298e20d7d7a81@mail.gmail.com> <55bd76f30801091359q109b0c0bh2a61b14f13f4226c@mail.gmail.com> <55bd76f30801091508h20c0a0a6n83be9ffe312487b2@mail.gmail.com> Message-ID: <55bd76f30801091545j55c20738t3962ae7e9d016820@mail.gmail.com> Thanks Douglas. Just tested it out, and the quality has improved dramatically on all GIF images I threw at it. On Jan 9, 2008 3:34 PM, douglas bagnall wrote: > Andy McCurdy wrote: > > > I interpreted your response as a setting to change to make this > > specific image resize better. I'm using PIL to resize images that > > users upload to my website. Since I don't have control over the > > media, I need generic settings that will be good for all users. What > > settings would you suggest to be best for all images, not just the > > example I provided? > > Using palette=Image.ADAPTIVE will be better for all images unless the > images are already in the web palette, or the viewers are from 1995 > and have 256 colour displays. Both of these are unlikely, and in any > case the adaptive system will work well enough for them. It will be > slower though. > > douglas > From fredrik at pythonware.com Thu Jan 10 08:45:18 2008 From: fredrik at pythonware.com (Fredrik Lundh) Date: Thu, 10 Jan 2008 08:45:18 +0100 Subject: [Image-SIG] Poor Image Quality When Resizing a GIF In-Reply-To: <55bd76f30801091545j55c20738t3962ae7e9d016820@mail.gmail.com> References: <55bd76f30801081542q625395f6m77ad0dda30d11dd7@mail.gmail.com> <55bd76f30801090832n768f08daoba298e20d7d7a81@mail.gmail.com> <55bd76f30801091359q109b0c0bh2a61b14f13f4226c@mail.gmail.com> <55bd76f30801091508h20c0a0a6n83be9ffe312487b2@mail.gmail.com> <55bd76f30801091545j55c20738t3962ae7e9d016820@mail.gmail.com> Message-ID: Andy McCurdy wrote: >> Using palette=Image.ADAPTIVE will be better for all images unless the >> images are already in the web palette, or the viewers are from 1995 >> and have 256 colour displays. Both of these are unlikely, and in any >> case the adaptive system will work well enough for them. It will be >> slower though. > > Thanks Douglas. Just tested it out, and the quality has improved > dramatically on all GIF images I threw at it. In addition to Douglas' excellent advice, you should probably also ask yourself if you really need to store the thumbnails as GIF images. For the general case, I'd probably use JPEG for everything (if it's good enough for Google, etc). If you have lots of non-photographic images in your database, you can use PNG for things that have 256 colors or less: if im.getcolors(256): # limited number of colors im = im.convert("P", palette=Image.ADAPTIVE, dither=Image.NONE) im.save(out, "PNG") else: im.save(out, "JPEG") (getcolors returns None if there are more than the given number of colors in the image. you can change 256 to something larger if you want to; 512 or 1024 probably works well in practice) From Scott.Daniels at Acm.Org Fri Jan 11 03:00:07 2008 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Thu, 10 Jan 2008 18:00:07 -0800 Subject: [Image-SIG] Poor Image Quality When Resizing a GIF In-Reply-To: References: <55bd76f30801081542q625395f6m77ad0dda30d11dd7@mail.gmail.com> <55bd76f30801090832n768f08daoba298e20d7d7a81@mail.gmail.com> <55bd76f30801091359q109b0c0bh2a61b14f13f4226c@mail.gmail.com> <55bd76f30801091508h20c0a0a6n83be9ffe312487b2@mail.gmail.com> <55bd76f30801091545j55c20738t3962ae7e9d016820@mail.gmail.com> Message-ID: Fredrik Lundh wrote: > For the general case, I'd probably use JPEG for everything (if it's good > enough for Google, etc). If you have lots of non-photographic images in > your database, you can use PNG for things that have 256 colors or less: > if im.getcolors(256): > # limited number of colors > im = im.convert("P", palette=Image.ADAPTIVE, dither=Image.NONE) > im.save(out, "PNG") > else: > im.save(out, "JPEG") PNG can cope with any number of colors (one of its advantages over GIF). I suspect your advice is to determine the photo/non-photo property by looking at the number of distinct colors. Unfortunately, the naive reader might infer that he couldn't put 300-color images in PNG. --Scott David Daniels Scott.Daniels at Acm.Org From natures2ndsun at sbcglobal.net Fri Jan 11 03:48:53 2008 From: natures2ndsun at sbcglobal.net (natures2ndsun) Date: Thu, 10 Jan 2008 18:48:53 -0800 Subject: [Image-SIG] [PIL installation] missing ANSI C headers on Solaris => Message-ID: <000701c853fc$815b7de0$6072e545@BARKER> III have Windows XP. recently I have been receiving warnings of Windows 95 - 98 ansi missing. My picture and fonts are distorted(grainy and large). I have downloaded whitesmoke recently and it is now refusing to display the web page. My initial opening screen and icons are normal, but then it goes black, briefly, to return as large and grainy, Can you help with this problem? -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/image-sig/attachments/20080110/c35e3a9f/attachment.htm From tiptip.barish at gmail.com Fri Jan 11 21:04:59 2008 From: tiptip.barish at gmail.com (Varsha purohit) Date: Fri, 11 Jan 2008 12:04:59 -0800 Subject: [Image-SIG] [image-sig] controlling brightness of the image Message-ID: <9636adca0801111204p4e7d950andf345ac681361bd5@mail.gmail.com> Hello All, I have written a program using ImageEnhance module of pil where i am controlling brightness and contrast of the image but i am unable to use im.save method to save the file. My code is here : import Image import ImageFilter import ImageEnhance file2 = "xyz.jpg" img2 = Image.open(file2) ench = ImageEnhance.Brightness(img2) ench1 = ench.filter(ImageFilter.SHARPEN) ench.save("xyz1.jpg" + ext, "JPEG", quality=100) It says Brightness doesnt have attributes save and filter ? Than how can i save the enhanced image... any ideas... -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/image-sig/attachments/20080111/b14dc5ef/attachment.htm From spe.stani.be at gmail.com Fri Jan 11 23:16:56 2008 From: spe.stani.be at gmail.com (Stani) Date: Fri, 11 Jan 2008 23:16:56 +0100 Subject: [Image-SIG] [image-sig] controlling brightness of the image In-Reply-To: <9636adca0801111204p4e7d950andf345ac681361bd5@mail.gmail.com> References: <9636adca0801111204p4e7d950andf345ac681361bd5@mail.gmail.com> Message-ID: <4787EAD8.20103@gmail.com> You have to save the image, so replace your last line with: img2.save("xyz1.jpg",quality=100) Stani Varsha purohit schreef: > Hello All, > I have written a program using ImageEnhance module of pil where i am > controlling brightness and contrast of the image but i am unable to use > im.save method to save the file. My code is here : > > import Image > import ImageFilter > import ImageEnhance > > file2 = "xyz.jpg" > img2 = Image.open(file2) > ench = ImageEnhance.Brightness(img2) > ench1 = ench.filter(ImageFilter.SHARPEN) > ench.save("xyz1.jpg" + ext, "JPEG", quality=100) > > > It says Brightness doesnt have attributes save and filter ? > > Than how can i save the enhanced image... any ideas... > > > ------------------------------------------------------------------------ > > _______________________________________________ > Image-SIG maillist - Image-SIG at python.org > http://mail.python.org/mailman/listinfo/image-sig > From fredrik at pythonware.com Sat Jan 12 09:29:28 2008 From: fredrik at pythonware.com (Fredrik Lundh) Date: Sat, 12 Jan 2008 09:29:28 +0100 Subject: [Image-SIG] [image-sig] controlling brightness of the image In-Reply-To: <9636adca0801111204p4e7d950andf345ac681361bd5@mail.gmail.com> References: <9636adca0801111204p4e7d950andf345ac681361bd5@mail.gmail.com> Message-ID: Varsha purohit wrote: > I have written a program using ImageEnhance module of pil where i > am controlling brightness and contrast of the image but i am unable to > use im.save method to save the file. My code is here : > > import Image > import ImageFilter > import ImageEnhance > > file2 = "xyz.jpg" > img2 = Image.open(file2) > ench = ImageEnhance.Brightness(img2) this creates an enhancement object that can be used to create enhanced images. you need to call the "enhance" method to actually get an image object. see the documentation for details: http://www.pythonware.com/library/pil/handbook/imageenhance.htm From tiptip.barish at gmail.com Fri Jan 11 23:37:13 2008 From: tiptip.barish at gmail.com (Varsha purohit) Date: Fri, 11 Jan 2008 14:37:13 -0800 Subject: [Image-SIG] [image-sig] controlling brightness of the image In-Reply-To: <4787EAD8.20103@gmail.com> References: <9636adca0801111204p4e7d950andf345ac681361bd5@mail.gmail.com> <4787EAD8.20103@gmail.com> Message-ID: <9636adca0801111437n330a9e03l50d7550af4fb235b@mail.gmail.com> Hi Stani, But i have enhanced the image with variable name ench1. So will the image be effected ?? thanks, On Jan 11, 2008 2:16 PM, Stani wrote: > You have to save the image, so replace your last line with: > img2.save("xyz1.jpg",quality=100) > > Stani > > Varsha purohit schreef: > > Hello All, > > I have written a program using ImageEnhance module of pil where i > am > > controlling brightness and contrast of the image but i am unable to use > > im.save method to save the file. My code is here : > > > > import Image > > import ImageFilter > > import ImageEnhance > > > > file2 = "xyz.jpg" > > img2 = Image.open(file2) > > ench = ImageEnhance.Brightness(img2) > > ench1 = ench.filter(ImageFilter.SHARPEN) > > ench.save("xyz1.jpg" + ext, "JPEG", quality=100) > > > > > > It says Brightness doesnt have attributes save and filter ? > > > > Than how can i save the enhanced image... any ideas... > > > > > > ------------------------------------------------------------------------ > > > > _______________________________________________ > > Image-SIG maillist - Image-SIG at python.org > > http://mail.python.org/mailman/listinfo/image-sig > > > > > _______________________________________________ > Image-SIG maillist - Image-SIG at python.org > http://mail.python.org/mailman/listinfo/image-sig > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/image-sig/attachments/20080111/f4c16b65/attachment.htm From spe.stani.be at gmail.com Sat Jan 12 00:15:44 2008 From: spe.stani.be at gmail.com (Stani) Date: Sat, 12 Jan 2008 00:15:44 +0100 Subject: [Image-SIG] [image-sig] controlling brightness of the image In-Reply-To: <9636adca0801111437n330a9e03l50d7550af4fb235b@mail.gmail.com> References: <9636adca0801111204p4e7d950andf345ac681361bd5@mail.gmail.com> <4787EAD8.20103@gmail.com> <9636adca0801111437n330a9e03l50d7550af4fb235b@mail.gmail.com> Message-ID: <4787F8A0.1010102@gmail.com> Sorry, I looked to quickly to your code. Your mistake is that you are mixin images and enhancers. For clarity I marked every image object with the suffix '_im': import Image import ImageFilter import ImageEnhance file2 = "xyz.jpg" im = Image.open(file2) enhancer = ImageEnhance.Brightness(im) bright_im = enhancer.enhance(0.5) #any value you want sharp_im = bright_im.filter(ImageFilter.SHARPEN) sharp_im.save("xyz1.jpg",quality=100) >From the documentation: All enhancement classes implement a common interface, containing a single method: enhancer.enhance(factor) => image Returns an enhanced image. The factor is a floating point value controlling the enhancement. Factor 1.0 always returns a copy of the original image, lower factors mean less color (brightness, contrast, etc), and higher values more. There are no restrictions on this value. http://www.pythonware.com/library/pil/handbook/imageenhance.htm Varsha purohit schreef: > Hi Stani, > But i have enhanced the image with variable name ench1. So will the > image be effected ?? > > thanks, > > On Jan 11, 2008 2:16 PM, Stani wrote: > > >> You have to save the image, so replace your last line with: >> img2.save("xyz1.jpg",quality=100) >> >> Stani >> >> Varsha purohit schreef: >> >>> Hello All, >>> I have written a program using ImageEnhance module of pil where i >>> >> am >> >>> controlling brightness and contrast of the image but i am unable to use >>> im.save method to save the file. My code is here : >>> >>> import Image >>> import ImageFilter >>> import ImageEnhance >>> >>> file2 = "xyz.jpg" >>> img2 = Image.open(file2) >>> ench = ImageEnhance.Brightness(img2) >>> ench1 = ench.filter(ImageFilter.SHARPEN) >>> ench.save("xyz1.jpg" + ext, "JPEG", quality=100) >>> >>> >>> It says Brightness doesnt have attributes save and filter ? >>> >>> Than how can i save the enhanced image... any ideas... >>> >>> >>> ------------------------------------------------------------------------ >>> >>> _______________________________________________ >>> Image-SIG maillist - Image-SIG at python.org >>> http://mail.python.org/mailman/listinfo/image-sig >>> >>> >> _______________________________________________ >> Image-SIG maillist - Image-SIG at python.org >> http://mail.python.org/mailman/listinfo/image-sig >> >> > > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/image-sig/attachments/20080112/b542096b/attachment.htm From anewc2 at gmail.com Sat Jan 12 00:24:53 2008 From: anewc2 at gmail.com (Amos Newcombe) Date: Fri, 11 Jan 2008 18:24:53 -0500 Subject: [Image-SIG] [image-sig] controlling brightness of the image In-Reply-To: <9636adca0801111204p4e7d950andf345ac681361bd5@mail.gmail.com> References: <9636adca0801111204p4e7d950andf345ac681361bd5@mail.gmail.com> Message-ID: According to the docs, this should be the code: import Image import ImageFilter import ImageEnhance file2 = "xyz.jpg" img2 = Image.open(file2) ench = ImageEnhance.Brightness(img2) img2 = ench.enhance(2) # change the factor 2 to fit your application img2 = img2.filter(ImageFilter.SHARPEN) img2.save("xyz1.jpg" + ext, "JPEG", quality=100) It says Brightness doesnt have attributes save and filter ? > A brightness enhancer doesn't. An image does. (I haven't checked your other steps. The save() call looks unnecessarily complicated, but I don't know what code you've cut out.) Amos -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/image-sig/attachments/20080111/5acf1361/attachment.htm From fredrik at pythonware.com Sat Jan 12 13:15:23 2008 From: fredrik at pythonware.com (Fredrik Lundh) Date: Sat, 12 Jan 2008 13:15:23 +0100 Subject: [Image-SIG] [image-sig] controlling brightness of the image In-Reply-To: References: <9636adca0801111204p4e7d950andf345ac681361bd5@mail.gmail.com> Message-ID: Amos Newcombe wrote: > > img2.save("xyz1.jpg" + ext, "JPEG", quality=100) > > (I haven't checked your other steps. The save() call looks unnecessarily > complicated, but I don't know what code you've cut out.) quality=100 is a bad idea, at least. quoting myself from an earlier post: JPEG quality 100 is overkill, btw -- it completely disables JPEG's quantization stage, and "mainly of interest for experimental pur- poses", according to the JPEG library documentation, which continues: "Quality values above about 95 are NOT recommended for normal use; the compressed file size goes up dramatically for hardly any gain in output image quality." As for suitable settings, the documentation recommends the following: "/.../ the quality setting should be between 50 and 95; the default of 75 is often about right. If you see defects at quality 75, then go up 5 or 10 counts at a time until you are happy with the output image. (The optimal setting will vary from one image to another.) For the full excerpt from that documentation, see: http://mail.python.org/pipermail/image-sig/2002-July/001916.html regards /F From fredrik at pythonware.com Sat Jan 12 13:29:48 2008 From: fredrik at pythonware.com (Fredrik Lundh) Date: Sat, 12 Jan 2008 13:29:48 +0100 Subject: [Image-SIG] [image-sig] controlling brightness of the image In-Reply-To: References: <9636adca0801111204p4e7d950andf345ac681361bd5@mail.gmail.com> Message-ID: Fredrik Lundh wrote: > "Quality values above about 95 are NOT recommended for > normal use; the compressed file size goes up dramatically > for hardly any gain in output image quality." to illustrate, here are the output sizes for the standard "LENNA" image, for some quality settings/formats: 50 22833 60 26253 75 35292 (default) 80 41162 85 49294 90 64280 95 99870 100 219203 PNG 491272 RAW 786432 (uncompressed, w/o header) From carl at personnelware.com Sat Jan 12 17:36:06 2008 From: carl at personnelware.com (Carl Karsten) Date: Sat, 12 Jan 2008 10:36:06 -0600 Subject: [Image-SIG] pdf to image Message-ID: <4788EC76.7030804@personnelware.com> For the PyCon registration web page, we would like to display a preview of what the persons badge will look like based on what they have entered. (full name, nick name, extra lines in the fonts that will be used - helps make sure things will fit, etc.) The badge gets created as a pdf=mkpdf(data set) - we can just give the person the pdf, but we are trying to put it on the web page with so we need to convert the pdf to an image. I can't find a clean way of doing it. I found no ghostscript bindings, and the 2 imagemagick bindings either screwed up stdio or segfaulted. The best I could do is below, and it is causing this to show up in the error log: close failed: [Errno 10] No child processes and stack dumps: > subprocess.call(gs_command) > > File "/usr/local/lib/python2.5/subprocess.py", line 443, in call > return Popen(*popenargs, **kwargs).wait() > > File "/usr/local/lib/python2.5/subprocess.py", line 1110, in wait > pid, sts = os.waitpid(self.pid, 0) > > OSError: [Errno 10] No child processes here is the current code: def sample(pdf): tempDir = tempfile.mkdtemp( prefix = "badgePreview_" ) pdfname = path.join( tempDir, 'badge.pdf' ) imgname = path.join( tempDir, 'badge.png' ) open(pdfname,'wb').write(pdf) # convert pdf to some image format (uses ext to determine type) # system('convert %s %s' % (pdfname, imgname)) # gs -sDEVICE=png16m -sOutputFile=x.png -dBATCH -dNOPAUSE badge.pdf gs_command = ['gs', '-q', '-sDEVICE=png16m', '-dBATCH', '-dNOPAUSE', '-sOutputFile=%s'%imgname, pdfname ] subprocess.call(gs_command) # crop the badge (pdf may be 8x11 page) # and write to a string that can be reutnred buffer = StringIO() Image.open(imgname).crop([0,0,300,235]).save(buffer, 'png') img = buffer.getvalue() # clean up buffer.close() remove(pdfname) remove(imgname) rmdir(tempDir) return img So.... anyone have some nifty code? Carl K From fredrik at pythonware.com Sat Jan 12 18:43:20 2008 From: fredrik at pythonware.com (Fredrik Lundh) Date: Sat, 12 Jan 2008 18:43:20 +0100 Subject: [Image-SIG] pdf to image In-Reply-To: <4788EC76.7030804@personnelware.com> References: <4788EC76.7030804@personnelware.com> Message-ID: Carl Karsten wrote: > close failed: [Errno 10] No child processes > > and stack dumps: > > > subprocess.call(gs_command) > > > > File "/usr/local/lib/python2.5/subprocess.py", line 443, in call > > return Popen(*popenargs, **kwargs).wait() > > > > File "/usr/local/lib/python2.5/subprocess.py", line 1110, in wait > > pid, sts = os.waitpid(self.pid, 0) > > > > OSError: [Errno 10] No child processes does the "gs" command behave properly if you run it from the shell? From carl at personnelware.com Sun Jan 13 16:53:01 2008 From: carl at personnelware.com (Carl Karsten) Date: Sun, 13 Jan 2008 09:53:01 -0600 Subject: [Image-SIG] pdf to image In-Reply-To: References: <4788EC76.7030804@personnelware.com> Message-ID: <478A33DD.4020206@personnelware.com> Fredrik Lundh wrote: > Carl Karsten wrote: > >> close failed: [Errno 10] No child processes >> >> and stack dumps: >> >> > subprocess.call(gs_command) >> > >> > File "/usr/local/lib/python2.5/subprocess.py", line 443, in call >> > return Popen(*popenargs, **kwargs).wait() >> > >> > File "/usr/local/lib/python2.5/subprocess.py", line 1110, in wait >> > pid, sts = os.waitpid(self.pid, 0) >> > >> > OSError: [Errno 10] No child processes > > does the "gs" command behave properly if you run it from the shell? > Yes. It even behaves most of the time when run from subprocess.call(gs_command). Carl K From fredrik at pythonware.com Sun Jan 13 17:10:51 2008 From: fredrik at pythonware.com (Fredrik Lundh) Date: Sun, 13 Jan 2008 17:10:51 +0100 Subject: [Image-SIG] pdf to image In-Reply-To: <478A33DD.4020206@personnelware.com> References: <4788EC76.7030804@personnelware.com> <478A33DD.4020206@personnelware.com> Message-ID: Carl Karsten wrote: >>> > OSError: [Errno 10] No child processes >> >> does the "gs" command behave properly if you run it from the shell? > > Yes. > > It even behaves most of the time when run from subprocess.call(gs_command). could it be this bug? http://bugs.python.org/issue1731717 if so, I guess switching to a plain old os.system would help. quick fix: replace subprocess.call(gs_command) with os.system(subprocess.list2cmdline(gs_command)) From Chris.Barker at noaa.gov Mon Jan 14 20:44:38 2008 From: Chris.Barker at noaa.gov (Christopher Barker) Date: Mon, 14 Jan 2008 11:44:38 -0800 Subject: [Image-SIG] pdf to image In-Reply-To: <4788EC76.7030804@personnelware.com> References: <4788EC76.7030804@personnelware.com> Message-ID: <478BBBA6.8020102@noaa.gov> OK, a bit (or a lot!), but once someone else brought it up--- Carl Karsten wrote: > # gs -sDEVICE=png16m -sOutputFile=x.png -dBATCH -dNOPAUSE badge.pdf I've used similar code. However, in my case, we're thumbnailing arbitrary pdfs, which could be any size -- usually they are US-letter or A4, but there can be poster-sized ones there too. So my question is: How to I tell ghostscript to make the resulting image a given size (say 100x100 or less), or how do I use ghostscript to tell me the size of the pdf at hand, and then I could calculate the DPI myself? Any ideas? To the OP: you don't seem to be specifying the DPI that you want. The default may be OK, but you may want to be explicit: -r150 gives you 150dpi. -Chris -- Christopher Barker, Ph.D. Oceanographer Emergency Response Division NOAA/NOS/OR&R (206) 526-6959 voice 7600 Sand Point Way NE (206) 526-6329 fax Seattle, WA 98115 (206) 526-6317 main reception Chris.Barker at noaa.gov From noahspurrier at gmail.com Wed Jan 16 23:54:34 2008 From: noahspurrier at gmail.com (Noah.org) Date: Wed, 16 Jan 2008 14:54:34 -0800 Subject: [Image-SIG] RMS difference patch Message-ID: I have a patch that adds an RMS Difference method to the PIL. Let me know if there is any interest in this. I originally wrote this to help implement a video stabilization filter. You could also use this to quantify how much a lossy compression algorithm distorts an image relative to some other compression algorithm. I thought others might find RMS Difference useful. http://www.noah.org/wiki/PIL_patches This is a patch against the Python Imaging Library Imaging-1.1.6. This adds the method ImageChops.difference_rms(im1, im2) which returns a float of the RMS difference between the two given images, im1 and im2. This is about 10 times faster than doing it in Python. The RMS Difference can be used to detect and compare changes in images (say, for motion detection) or to compare the effect of different image operations. If the two images are exactly equal then difference_rms() will return 0.0. As the images diverge the RMS value returned will increase. It will always be a positive number. In general, the greater the difference between the two images then the greater the RMS difference will be. In video stabilization I take two frames of a video and shift one of them around until the RMS Difference is minimized. -- Noah Spurrier | email: noah at noah.org From douglas at paradise.net.nz Thu Jan 17 01:27:16 2008 From: douglas at paradise.net.nz (Douglas Bagnall) Date: Thu, 17 Jan 2008 13:27:16 +1300 Subject: [Image-SIG] RMS difference patch In-Reply-To: References: Message-ID: <478EA0E4.7080907@paradise.net.nz> hi Noah > I have a patch that adds an RMS Difference method to the PIL. > Let me know if there is any interest in this. I originally wrote this to > help implement a video stabilization filter. You could also use > this to quantify how much a lossy compression algorithm distorts > an image relative to some other compression algorithm. I thought > others might find RMS Difference useful. > > http://www.noah.org/wiki/PIL_patches > > This is a patch against the Python Imaging Library Imaging-1.1.6. > This adds the method ImageChops.difference_rms(im1, im2) which > returns a float of the RMS difference between the two given > images, im1 and im2. This is about 10 times faster than doing it > in Python. The RMS Difference can be used to detect and compare > changes in images (say, for motion detection) or to compare the > effect of different image operations. If the two images are > exactly equal then difference_rms() will return 0.0. As the > images diverge the RMS value returned will increase. It will > always be a positive number. In general, the greater the > difference between the two images then the greater the RMS > difference will be. Very good. It is something I could use. But there may be trouble with integer overflow. You are summing squared differences in a signed long, which wraps at 2**31. And: >>> 2**31 / (255 * 255) 33025L >>> 33025 ** 0.5 181.72781845386248 So won't comparing black and white 182 x 182 images will wrap the integer into a negative value and cause a floating point error in the square root. Slightly larger pictures will wrap it right round to 0, and just give you a false answer. Comparing pure black and white might seem capricious, but with larger images the differnce doesn't need to be so great to overflow. For example, with a 1024x1024 image: >>> 2 ** (31-20) ** 0.5 9.9633077752473778 A pixel difference of 10 across the 1 megapixel image will wrap the sum and crash. So what can be done? Using an unsigned long would add a little bit of room and take away the possibility of a negative sum, but it isn't much better. The other ways would be to use a long long (uint64_t) or double to sum in, both of which might be a bit slower. I think doubles can sum integral values up to around 2**52 (or 53?). That means your black and white images can be quite big: >>> ((2**52) / (255*255)) ** 0.5 263172.01568555878 and the error is less painful (because what happens at that limit is just that the limit + 1 equals the limit). I haven't tested your code or anything, but this is a kind of problem I have met in the past. I'd recommend you try doubles or longer ints and see whether the slow down is tolerable. I suspect it will be, and that you could offset it anyway by taking the "++ count" out of the loop and using instead: count = imIn1->xsize * imIn1->ysize; regards, Douglas From douglas at paradise.net.nz Thu Jan 17 01:37:01 2008 From: douglas at paradise.net.nz (Douglas Bagnall) Date: Thu, 17 Jan 2008 13:37:01 +1300 Subject: [Image-SIG] RMS difference patch In-Reply-To: <478EA0E4.7080907@paradise.net.nz> References: <478EA0E4.7080907@paradise.net.nz> Message-ID: <478EA32D.901@paradise.net.nz> I wrote: > >>>> 2 ** (31-20) ** 0.5 > 9.9633077752473778 > > A pixel difference of 10 across the 1 megapixel image will wrap the sum > and crash. But now I've read it and it looks like it should have been >>> (2 ** (31-20)) ** 0.5 45.254833995939045 So, not so bad, but nonetheless a problem. douglas From fredrik at pythonware.com Thu Jan 17 11:14:54 2008 From: fredrik at pythonware.com (Fredrik Lundh) Date: Thu, 17 Jan 2008 11:14:54 +0100 Subject: [Image-SIG] RMS difference patch In-Reply-To: References: Message-ID: Noah.org wrote: > I have a patch that adds an RMS Difference method to the PIL. > Let me know if there is any interest in this. I originally wrote this to > help implement a video stabilization filter. You could also use > this to quantify how much a lossy compression algorithm distorts > an image relative to some other compression algorithm. I thought > others might find RMS Difference useful. > > http://www.noah.org/wiki/PIL_patches > > This is a patch against the Python Imaging Library Imaging-1.1.6. > This adds the method ImageChops.difference_rms(im1, im2) which > returns a float of the RMS difference between the two given > images, im1 and im2. isn't this equivalent to ImageStat.Stat(ImageChops.difference(i, im)).rms ? (I'm busy with other stuff, so I might be missing something here). From imgrey at gmail.com Sat Jan 19 11:31:35 2008 From: imgrey at gmail.com (Vitaliyi) Date: Sat, 19 Jan 2008 12:31:35 +0200 Subject: [Image-SIG] format is None after convert('RGB') Message-ID: <3aac340801190231r46a4809fs4d36715e1cf1eda6@mail.gmail.com> Hi """ from PIL import Image img = Image.open('/tmp/tst.png') #after following conversion format is unknown. is it correct ? if img.mode != 'RGB': img = img.convert('RGB') P.S. I'm using python-imaging 1.1.6-1 (from debian) Thanks From fredrik at pythonware.com Sat Jan 19 12:16:51 2008 From: fredrik at pythonware.com (Fredrik Lundh) Date: Sat, 19 Jan 2008 12:16:51 +0100 Subject: [Image-SIG] format is None after convert('RGB') In-Reply-To: <3aac340801190231r46a4809fs4d36715e1cf1eda6@mail.gmail.com> References: <3aac340801190231r46a4809fs4d36715e1cf1eda6@mail.gmail.com> Message-ID: Vitaliyi wrote: > from PIL import Image > img = Image.open('/tmp/tst.png') > > #after following conversion format is unknown. is it correct ? > if img.mode != 'RGB': > img = img.convert('RGB') > > P.S. I'm using python-imaging 1.1.6-1 (from debian) the "format" attribute only reflects the immediate source. like most PIL operations, "convert" returns a *new* image object. From drever at in.tum.de Mon Jan 21 16:56:59 2008 From: drever at in.tum.de (drever) Date: Mon, 21 Jan 2008 16:56:59 +0100 Subject: [Image-SIG] aggdraw Message-ID: <4794C0CB.4030304@in.tum.de> Hello! I'm using PIL to load and save images. To draw images I use ImageDraw, but I am not content with the drawing quality. aggdraw uses agg which is a high quality drawing engine. I could not install it, so is there an alternative or can anybody help? I tried to install it on ubuntu 7.10 with python 2.5.1. After building the package the ./selftest.py crashed with a segfault. When I import aggdraw to python, I can use it with Image without crashes, but I don't see anything on the Image. Thanks for any advice! Johannes From coen at reservoir.nl Mon Jan 21 17:45:39 2008 From: coen at reservoir.nl (Coen van der Kamp) Date: Mon, 21 Jan 2008 17:45:39 +0100 Subject: [Image-SIG] aggdraw In-Reply-To: <4794C0CB.4030304@in.tum.de> References: <4794C0CB.4030304@in.tum.de> Message-ID: <4794CC33.9040304@reservoir.nl> drever wrote: > Hello! > > I'm using PIL to load and save images. To draw images I use ImageDraw, > but I am not content with the drawing quality. aggdraw uses agg which is > a high quality drawing engine. I could not install it, so is there an > alternative or can anybody help? > > I tried to install it on ubuntu 7.10 with python 2.5.1. After building > the package the ./selftest.py crashed with a segfault. > > When I import aggdraw to python, I can use it with Image without > crashes, but I don't see anything on the Image. > > Thanks for any advice! > > Johannes > _______________________________________________ > Image-SIG maillist - Image-SIG at python.org > http://mail.python.org/mailman/listinfo/image-sig > > Hello Drever, You don't have errors when importing aggdraw and Image? Than this has to work: import aggdraw, Image im = Image.new("RGB", (100, 100), ("white")) draw = aggdraw.Draw(im) pen = aggdraw.Pen('black', width=5, opacity=255) draw.ellipse((10,10,90,90), pen) draw.flush() # Without the flush you'll get an empty image! # im.show() # Has compression im.save("/path/to/your/folder/test.png", "png") # Clean aggdraw image Hope it helps! Coen From drever at in.tum.de Tue Jan 22 10:28:42 2008 From: drever at in.tum.de (drever) Date: Tue, 22 Jan 2008 10:28:42 +0100 Subject: [Image-SIG] aggdraw In-Reply-To: <4794CC33.9040304@reservoir.nl> References: <4794C0CB.4030304@in.tum.de> <4794CC33.9040304@reservoir.nl> Message-ID: <4795B74A.8050800@in.tum.de> Hello Coen, thank you, that helped! I didn't notice the flush statement. Johannes Coen van der Kamp wrote: > drever wrote: >> Hello! >> >> I'm using PIL to load and save images. To draw images I use >> ImageDraw, but I am not content with the drawing quality. aggdraw >> uses agg which is a high quality drawing engine. I could not install >> it, so is there an alternative or can anybody help? >> >> I tried to install it on ubuntu 7.10 with python 2.5.1. After >> building the package the ./selftest.py crashed with a segfault. >> >> When I import aggdraw to python, I can use it with Image without >> crashes, but I don't see anything on the Image. >> >> Thanks for any advice! >> >> Johannes >> _______________________________________________ >> Image-SIG maillist - Image-SIG at python.org >> http://mail.python.org/mailman/listinfo/image-sig >> >> > Hello Drever, > > You don't have errors when importing aggdraw and Image? Than this has > to work: > > import aggdraw, Image > im = Image.new("RGB", (100, 100), ("white")) > draw = aggdraw.Draw(im) > pen = aggdraw.Pen('black', width=5, opacity=255) > draw.ellipse((10,10,90,90), pen) > draw.flush() # Without the flush you'll get an empty image! > # im.show() # Has compression > im.save("/path/to/your/folder/test.png", "png") # Clean aggdraw image > > Hope it helps! > Coen From sylvain.berger at alpha-vision.com Thu Jan 17 01:58:29 2008 From: sylvain.berger at alpha-vision.com (Sylvain Berger) Date: Wed, 16 Jan 2008 19:58:29 -0500 Subject: [Image-SIG] Maya iff support for PIL Message-ID: <3E284826C76A844A9D14DB667E6AFE7F01BC178A@alpha-dc.alpha-vision.com> Hi, I am looking for a way to add the Maya iff format to PIL. Any help would be appreciated Sylvain Berger | Technical Director | Alpha Vision Alpha Vision, 420 Armand Frappier suite 250, Laval, Canada H7V 4B4 (450) 902-0222 ext.248 -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/image-sig/attachments/20080116/99756c11/attachment.htm From Steven.Watanabe at autodesk.com Tue Jan 22 15:24:46 2008 From: Steven.Watanabe at autodesk.com (Steven Watanabe) Date: Tue, 22 Jan 2008 06:24:46 -0800 Subject: [Image-SIG] PIL and HDR images Message-ID: <800886C2A4A73E44BA0FE45152C023702503AD651A@ADSK-NAMSG-02.MGDADSK.autodesk.com> PIL 1.1.6 out of the box does not appear to support HDR images, correct? Does anyone know if an HDR image plugin is available anywhere? -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/image-sig/attachments/20080122/900f0233/attachment.htm From adam at volition-inc.com Wed Jan 23 00:01:08 2008 From: adam at volition-inc.com (Adam Pletcher) Date: Tue, 22 Jan 2008 17:01:08 -0600 Subject: [Image-SIG] writing TGAs? Message-ID: <893A44FF792E904A97B7515CE341914602250306@volimxs01.thqinc.com> Does anyone know if writing .TGA files will be supported in a future release? That would sure help me out, at least. -- Adam Pletcher Technical Art Director Volition/THQ From pyprog05 at gmail.com Wed Jan 23 00:11:07 2008 From: pyprog05 at gmail.com (PyProg PyProg) Date: Wed, 23 Jan 2008 00:11:07 +0100 Subject: [Image-SIG] writing TGAs? In-Reply-To: <893A44FF792E904A97B7515CE341914602250306@volimxs01.thqinc.com> References: <893A44FF792E904A97B7515CE341914602250306@volimxs01.thqinc.com> Message-ID: 2008/1/23, Adam Pletcher : > Does anyone know if writing .TGA files will be supported in a future > release? > > That would sure help me out, at least. I'm also interested with this. a+ -- http://ekd.tolosano.info From gwidion at mpc.com.br Wed Jan 23 00:20:41 2008 From: gwidion at mpc.com.br (Joao S. O. Bueno) Date: Tue, 22 Jan 2008 20:20:41 -0300 Subject: [Image-SIG] writing TGAs? In-Reply-To: <893A44FF792E904A97B7515CE341914602250306@volimxs01.thqinc.com> References: <893A44FF792E904A97B7515CE341914602250306@volimxs01.thqinc.com> Message-ID: <200801222020.41468.gwidion@mpc.com.br> On Tuesday 22 January 2008 20:01, Adam Pletcher wrote: > Does anyone know if writing .TGA files will be supported in a > future release? > > That would sure help me out, at least. > Hi there. I am a coder, and work as a freelancer. I don't know if TGA support is supposed to be added to PIL - I'd say that not since TGA is no longer a popular format. However, as we are dealing with Free Software, you could hire someone to write this support for a fee. It even be cheap - and therefore you'd have he feature you need, and donate it to the World. Other options would be using other python-2d image libraries. I don't know if any besides GIMP-Python can write TGAs though, and that one must be run as a GIMP plug-in (so, you need to fire up a GIMP proccess). Regards, js -><- > Adam Pletcher > Technical Art Director > Volition/THQ From spe.stani.be at gmail.com Wed Jan 23 13:28:44 2008 From: spe.stani.be at gmail.com (Stani) Date: Wed, 23 Jan 2008 13:28:44 +0100 Subject: [Image-SIG] Problem with CMYK jpeg images Message-ID: <479732FC.8020606@gmail.com> Hi, PIL distorts the colours of a collection of CMYK jpeg images, even when you just try: im = Image.open(filename) im.save(filename) You can get an example image here: http://launchpadlibrarian.net/11232536/Marino_Detail02.jpg How can I fix this? Is there a workaround? Or is this a bug in PIL? Thanks for any help, Stani From smmoore at tiscali.co.za Thu Jan 24 09:47:45 2008 From: smmoore at tiscali.co.za (Samuel Moore) Date: Thu, 24 Jan 2008 10:47:45 +0200 Subject: [Image-SIG] PIL - How do I resize an image while keeping the IPTC and EXIF info? Message-ID: <000601c85e65$cad3dfd0$0300a8c0@blindlemonsam> Hi, I'm using the Python Imaging Library (PIL v1.1.6) to batch resize images. Problem is, it erases the IPTC and EXIF data for the resized file. I want the data to stay. Help?? -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/image-sig/attachments/20080124/2d735149/attachment.htm From wrybread at gmail.com Sun Jan 27 01:58:42 2008 From: wrybread at gmail.com (Alec Bennett) Date: Sat, 26 Jan 2008 16:58:42 -0800 Subject: [Image-SIG] PIL - How do I resize an image while keeping the IPTC and EXIF info? In-Reply-To: <000601c85e65$cad3dfd0$0300a8c0@blindlemonsam> References: <000601c85e65$cad3dfd0$0300a8c0@blindlemonsam> Message-ID: I don't know if the PIL has a way to preserve it, but if not you could of course read the data before resizing then write the data to the new image. http://simonwillison.net/2003/Nov/13/exif/ 2008/1/24 Samuel Moore : > > > Hi, > I'm using the Python Imaging Library (PIL v1.1.6) to batch resize images. > Problem is, it erases the IPTC and EXIF data for the resized file. I want > the data to stay. Help?? > _______________________________________________ > Image-SIG maillist - Image-SIG at python.org > http://mail.python.org/mailman/listinfo/image-sig > > From fredrik at pythonware.com Mon Jan 28 23:07:23 2008 From: fredrik at pythonware.com (Fredrik Lundh) Date: Mon, 28 Jan 2008 23:07:23 +0100 Subject: [Image-SIG] PIL - How do I resize an image while keeping the IPTC and EXIF info? In-Reply-To: <000601c85e65$cad3dfd0$0300a8c0@blindlemonsam> References: <000601c85e65$cad3dfd0$0300a8c0@blindlemonsam> Message-ID: Samuel Moore wrote: > I'm using the Python Imaging Library (PIL v1.1.6) to batch resize > images. Problem is, it erases the IPTC and EXIF data for the resized > file. I want the data to stay. Help?? PIL cannot save IPTC/EXIF data, so there's no way to do this "out of the box". (patches are welcome, as usual). From ndo at gmx.de Tue Jan 29 13:21:30 2008 From: ndo at gmx.de (Nando) Date: Tue, 29 Jan 2008 13:21:30 +0100 Subject: [Image-SIG] Maya iff support for PIL In-Reply-To: <3E284826C76A844A9D14DB667E6AFE7F01BC178A@alpha-dc.alpha-vision.com> References: <3E284826C76A844A9D14DB667E6AFE7F01BC178A@alpha-dc.alpha-vision.com> Message-ID: <479F1A4A.5000405@gmx.de> wow, Maya iff support would be extraordinary cool. Maybe this could help: http://www.stdout.org/~luke/iff2tga/ Cheers, Nando. Sylvain Berger wrote: > Hi, I am looking for a way to add the Maya iff format to PIL. > > > > Any help would be appreciated > > > > *Sylvain Berger** **| Technical Director | Alpha Vision* > > Alpha Vision, 420 Armand Frappier suite 250, Laval, Canada H7V 4B4 > > (450) 902-0222 ext.248 > > > > > ------------------------------------------------------------------------ > > _______________________________________________ > Image-SIG maillist - Image-SIG at python.org > http://mail.python.org/mailman/listinfo/image-sig From kwangyul.seo at gmail.com Tue Jan 29 04:15:03 2008 From: kwangyul.seo at gmail.com (KwangYul Seo) Date: Tue, 29 Jan 2008 12:15:03 +0900 Subject: [Image-SIG] Conversion to ARGB format. Message-ID: <7beb12420801281915w12484dd5n570ef9819709f4f@mail.gmail.com> Hi, Is it possible to convert a RGB image to ARGB format? The following code did not work. import PIL.Image im = PIL.Imageim.new("RGB", (100, 100)) im.convert("ARGB") Thanks, Kwang Yul Seo -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/image-sig/attachments/20080129/f730598c/attachment.htm From spe.stani.be at gmail.com Wed Jan 30 03:50:00 2008 From: spe.stani.be at gmail.com (SPE Stani's Python Editor) Date: Wed, 30 Jan 2008 03:50:00 +0100 Subject: [Image-SIG] Problem with CMYK jpeg images In-Reply-To: <479732FC.8020606@gmail.com> References: <479732FC.8020606@gmail.com> Message-ID: <2078a7ad0801291850v204950e8ye493ce9e84fa9f7a@mail.gmail.com> After digging in the archives, I found a solution in this thread: http://www.mail-archive.com/image-sig at python.org/msg01213.html Is there any reason why this was rejected? Stani On Jan 23, 2008 1:28 PM, Stani wrote: > Hi, > PIL distorts the colours of a collection of CMYK jpeg images, even when > you just try: > im = Image.open(filename) > im.save(filename) > > You can get an example image here: > http://launchpadlibrarian.net/11232536/Marino_Detail02.jpg > > How can I fix this? Is there a workaround? Or is this a bug in PIL? > > Thanks for any help, > Stani > -- http://pythonide.stani.be From rsenra at acm.org Wed Jan 30 02:54:39 2008 From: rsenra at acm.org (Rodrigo Dias Arruda Senra) Date: Tue, 29 Jan 2008 23:54:39 -0200 Subject: [Image-SIG] Conversion to ARGB format. In-Reply-To: <7beb12420801281915w12484dd5n570ef9819709f4f@mail.gmail.com> References: <7beb12420801281915w12484dd5n570ef9819709f4f@mail.gmail.com> Message-ID: <20080129235439.354e7158@Neo> [ KwangYul Seo ]: --------------------- >Hi, > >Is it possible to convert a RGB image to ARGB format? The following >code did not work. > >import PIL.Image >im = PIL.Imageim.new("RGB", (100, 100)) >im.convert("ARGB") Hi, have you tried RGBA instead of ARGB ? cheers, Senra From wrybread at gmail.com Wed Jan 30 07:34:22 2008 From: wrybread at gmail.com (Alec Bennett) Date: Wed, 30 Jan 2008 07:34:22 +0100 Subject: [Image-SIG] Conversion to ARGB format. In-Reply-To: <7beb12420801281915w12484dd5n570ef9819709f4f@mail.gmail.com> References: <7beb12420801281915w12484dd5n570ef9819709f4f@mail.gmail.com> Message-ID: im = Image.open("whatever.jpg").convert('RGBA') 2008/1/29 KwangYul Seo : > Hi, > > Is it possible to convert a RGB image to ARGB format? The following code > did not work. > > import PIL.Image > im = PIL.Imageim.new("RGB", (100, 100)) > im.convert("ARGB") > > > Thanks, > Kwang Yul Seo > > > _______________________________________________ > Image-SIG maillist - Image-SIG at python.org > http://mail.python.org/mailman/listinfo/image-sig > > From ned at nedbatchelder.com Thu Jan 31 00:24:38 2008 From: ned at nedbatchelder.com (Ned Batchelder) Date: Wed, 30 Jan 2008 18:24:38 -0500 Subject: [Image-SIG] Truly transparent text with PIL Message-ID: <47A10736.1050209@nedbatchelder.com> I know this is a subject that comes up occasionally on this list, so I thought readers would be interested in how to make truly transparent text with PIL: http://nedbatchelder.com/blog/200801/truly_transparent_text_with_pil.html --Ned. -- Ned Batchelder, http://nedbatchelder.com From jjhuff at mspin.net Thu Jan 31 21:11:43 2008 From: jjhuff at mspin.net (Justin Huff) Date: Thu, 31 Jan 2008 12:11:43 -0800 Subject: [Image-SIG] [patch] JPEG Chroma Subsampling Message-ID: <47A22B7F.6080709@mspin.net> Attached is a patch (against PIL 1.1.6) to provide control over the chroma subsampling done by the JPEG encoder. This is often useful for reducing compression artifacts around edges of clipart and text. Comments appreciated! --Justin -------------- next part -------------- An embedded and charset-unspecified text was scrubbed... Name: PIL-jpeg-subsampling.patch Url: http://mail.python.org/pipermail/image-sig/attachments/20080131/d3b53da8/attachment.txt From seed95 at gmail.com Wed Jan 30 09:51:42 2008 From: seed95 at gmail.com (Seed) Date: Wed, 30 Jan 2008 09:51:42 +0100 Subject: [Image-SIG] Make the difference between a picture and a photo In-Reply-To: <52e42efe0801291656i3b8c149cn6b4e2190f0c40527@mail.gmail.com> References: <52e42efe0801291656i3b8c149cn6b4e2190f0c40527@mail.gmail.com> Message-ID: <52e42efe0801300051saa0721bre672ffac18c6541d@mail.gmail.com> Hi, Is there a way with or without PIL python librairy to detect if an image looks like a picture more than a photography and the opposite? Any help will be appreciated. Thanks in advance. -- Sidney Amani -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/image-sig/attachments/20080130/c912362a/attachment.htm