[Image-SIG] Reading title EXIF data

Geert Dekkers geert at nznl.com
Wed Jun 3 07:51:37 CEST 2009


Hi all

I have a django asset management tool that uses the exiftool command  
line to extract metadata which does get the title, and a host of other  
tags. Exiftool is great because it's complete and really well  
maintained. The downside is of course that it's perl. I use the  
command line interface through subprocess, works really well.

Geert



On Jun 3, 2009, at 12:35 AM, image-sig-request at python.org wrote:

> Send Image-SIG mailing list submissions to
> 	image-sig at python.org
>
> To subscribe or unsubscribe via the World Wide Web, visit
> 	http://mail.python.org/mailman/listinfo/image-sig
> or, via email, send a message with subject or body 'help' to
> 	image-sig-request at python.org
>
> You can reach the person managing the list at
> 	image-sig-owner at python.org
>
> When replying, please edit your Subject line so it is more specific
> than "Re: Contents of Image-SIG digest..."
> Today's Topics:
>
>   1. Re: Lanczos interpolation (Franz Buchinger)
>   2. Re: Reading title EXIF data (Franz Buchinger)
>   3. Python Core Graphics Question (resent) (Geert Dekkers)
>
> From: Franz Buchinger <fbuchinger at gmail.com>
> Date: June 2, 2009 1:58:38 PM GMT+02:00
> To: image-sig at python.org
> Subject: Re: [Image-SIG] Lanczos interpolation
>
>
> A good old trick is to work with intermediate images: resize the  
> image using the Bilinear method and produce an intermediate image  
> that is about 25% larger than the final image.
> Then you can downscale the intermediate image using Lanczos.
>
> This should give a much better performance than working just with  
> Lanczos, especially for large downscaling ratios (e.g. 10 Megapixel  
> JPEG -> 1024x768) .
> Image quality shouldn't be affected too much by this method.
>
>
> Franz
>
> 2009/5/12 Fredrik Lundh <fredrik at pythonware.com>
> On Sun, May 10, 2009 at 12:45 PM, David Yan <davidyan6 at gmail.com>  
> wrote:
> > I want to resize an image Lanczos interpolation but I haven't  
> found any
> > python module that can do so.  Also, I'm not knowledgeable enough  
> to write
> > one myself.  What's the best way I can do this?  I use PIL  
> currently but the
> > resampling filters don't suit my needs (antialias is too slow,  
> bilinear and
> > bicubic produce aliasing when downsampling).
>
> ANTIALIAS is a Lanczos interpolation written in C, so it's not
> entirely obvious to me how you expect a Python version to be faster...
>
> </F>
> _______________________________________________
> Image-SIG maillist  -  Image-SIG at python.org
> http://mail.python.org/mailman/listinfo/image-sig
>
>
>
>
> From: Franz Buchinger <fbuchinger at gmail.com>
> Date: June 2, 2009 2:12:34 PM GMT+02:00
> To: image-sig at python.org
> Subject: Re: [Image-SIG] Reading title EXIF data
>
>
> PIL is an excellent image processing library, but unfortunatly not a  
> tool of choice when you want to deal with EXIF data seriously.
>
> It only extracts a subset of the EXIF-Data contained in an image,  
> for a more complete library you may want to check pyexiv2 (python  
> wrapper for exiv2).
>
> And beware, EXIF (as well as other metadata standards like IPTC) is  
> full of "dead tags" that are only written by some exotic image  
> processing applications or camera models.
>
> In your special case ("finding a title for a photo"), I'd resort to  
> IPTC:Caption - this is where Photoshop/Lightroom/Google Picasa and  
> many other image processing apps store "title" information.
>
> Franz
>
> 2009/5/22 Luke Hutscal <luke at liftinteractive.com>
> Hello, all.
>
> I am currently working on a Django application that stores photos as  
> users upload them.
>
> One of the cooler features that we'd like to add is automatic EXIF  
> reading - so instead of users having to go through and update their  
> photo's information again after uploading them, the EXIF data on the  
> uploaded photos can get automatically read into certain fields -  
> title, caption, and so on.
>
> I have been using the Image._getexif() method to retrieve the EXIF  
> data for the photos that are being uploaded - but it seems that the  
> "title" attribute is missing. Here's an example of what _getexif()  
> returns:
>
> http://liftslice3.com/getexif.txt
>
> However, when I run ExifTool(http://www.sno.phy.queensu.ca/~phil/exiftool/ 
> ) on the image with the -d flag, this is what is output:
>
> http://liftslice3.com/exiftool.txt
>
> As you can see, there's definitely a title attribute present on the  
> image in question. I took a look at the EXIF tags list at http://www.element-it.com/StandardImageTags.ASPX 
> , and noticed that the ImageTitle EXIF tag isn't present in PIL's  
> ExifTags.py - is there a reason for this? I tried adding a key for  
> 0x0320 with the value "ImageTitle" to the TAGS dict, but PIL still  
> doesn't seem to be reading the ImageTitle attribute out of my images.
>
> Is there something I've missed that is keeping PIL from reading the  
> title attribute?
>
> Thanks,
>
> Luke
>
>
> _______________________________________________
> Image-SIG maillist  -  Image-SIG at python.org
> http://mail.python.org/mailman/listinfo/image-sig
>
>
>
>
>
> From: Geert Dekkers <geert at nznl.com>
> Date: June 2, 2009 9:13:50 PM GMT+02:00
> To: image-sig at python.org
> Cc: pythonmac-sig at python.org
> Subject: [Image-SIG] Python Core Graphics Question (resent)
>
>
> Hi all
> (I just resent this message as I couldn't it find it on the digest  
> even after days - again, I apologise for any cross-posting)
> Below is a piece of code that I found over in the quartz-dev list.  
> I've been using this function unchanged in a batch processor, and it  
> appears to leak memory quite substantially. So much so that my test  
> machine (1Gb memory) , a mac mini, and my production xserve (2 Gb  
> memory) both crashed using it. My dev machine, an imac (4Gb memory)  
> slowed, but stayed up.
> I think I have the problem down to "croppedimg =  
> srcimg.createWithImageInRect(cliprect)". If used with an image of  
> suffient size, it quickly sucks up all available memory.
> Has anyone experienced similar problems using this method? Its Obj-C  
> name is "CGContextCreateWithImageInRect". And I should think that  
> one would only see something bad happening in some sort of batch  
> processing.
> Incidentally, my workaround was to lower the size of the source  
> image. But the process is still quite unstable. It brought down my  
> xserve after processing 7000 of the 7600 odd items.
> I've pasted the original post below. And sorry for any cross -  
> posting.
> Cheers, Geert
> ----------------------------------------------------------------------------------------------
> Geert Dekkers Web Studio | 2e Keucheniusstraat 8HS 1051VR Amsterdam  
> | +31(0)627224301 | http://nznl.net
> ----------------------------------------------------------------------------------------------
>
>
>>> Thanks for you detailed reply Glen - much appreciated.
>>> You helped me to solve what i was trying to do by using  
>>> CGImageCreateWithImageinRect as suggested.
>>>
>>> For anyone else interested here is some simple python code for  
>>> making cropped thumbnails of any proportion and not loosing the  
>>> aspect ratio of the original image.
>>> ...and its damn fast!
>>>
>>> ----------- #!/usr/bin/python
>>>
>>> from __future__ import division import CoreGraphics
>>>
>>> def resizeimage(srcimage,targetimage, tw, th):
>>>
>>> srcimg =  
>>> CoreGraphics 
>>>  .CGImageImport 
>>> (CoreGraphics.CGDataProviderCreateWithFilename(srcimage))
>>>
>>> sw = srcimg.getWidth()
>>> sh = srcimg.getHeight()
>>>
>>> aspect = tw/th
>>>
>>> widthfactor = tw/sw	
>>> heightfactor = th/sh
>>>
>>> if widthfactor < heightfactor:
>>> #src height stays the same
>>> #src width gets cropped
>>> cropwidth = sh * aspect
>>> x1 = ((sw-cropwidth)/2)
>>> y1 = 0
>>> x2 = sw-((sw-cropwidth))
>>> y2 = sh
>>> else:
>>> #src height gets cropped
>>> #src width stays the same
>>> cropheight = sw / aspect
>>> x1 = 0
>>> y1 = ((sh-cropheight)/2)
>>> x2 = sw
>>> y2 = sh-((sh-cropheight))	
>>>
>>> cliprect = CoreGraphics.CGRectMake(x1, y1, x2, y2)
>>> croppedimg = srcimg.createWithImageInRect(cliprect)	
>>>
>>> cs = CoreGraphics.CGColorSpaceCreateDeviceRGB()
>>> c = CoreGraphics.CGBitmapContextCreateWithColor(tw, th, cs,  
>>> (0,0,0,0))
>>>
>>> c.setInterpolationQuality(CoreGraphics.kCGInterpolationLow)
>>> newRect = CoreGraphics.CGRectMake(0, 0, tw, th)
>>> c.drawImage(newRect, croppedimg)
>>> c.writeToFile(targetimage, CoreGraphics.kCGImageFormatJPEG)
>>>
>>> resizeimage("/users/adam/Desktop/bootlogo4pa8.jpg", "/users/adam/  
>>> Desktop/aaaaa.jpg" , 80,80)	
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>> On Aug 12, 2008, at 3:41 AM, Glenn Cole wrote:
>>>>
>>>> Hi, Adam --
>>>>
>>>> I'm no expert, but until others more knowledgeable respond,  
>>>> here's my understanding.
>>>>
>>>> First, I suspect the fact that you're using Python won't matter  
>>>> at all here. (It does in other circumstances, but I don't think  
>>>> so here.)
>>>>
>>>> It sounds like you're looking for more support from Quartz for  
>>>> your task than what's really there. In the end, I think it's  
>>>> going to be more a choice of algorithm on your part.
>>>>
>>>> For example, given different aspect ratios, the new image could  
>>>> either:
>>>>
>>>> 1. ignore the difference (i.e., the current behaviour)
>>>> 2. show the entire original image within the new target,  
>>>> respecting the aspect ratio
>>>> 3. clip the original image to match the new aspect ratio
>>>>
>>>> For #2, you could shrink the target rect to match the aspect  
>>>> ratio of the original image.
>>>>
>>>> For #3 (your goal), you could clip the original image to match  
>>>> the target aspect ratio. However, page 250 of the outstanding  
>>>> Programming With Quartz notes a few downsides to this, and  
>>>> suggests using CGImageCreateWithImageInRect instead (first  
>>>> available in Tiger) to define a "subimage" of the original image.  
>>>> Again, though, you would need to determine yourself that the  
>>>> subimage should ignore 100 pixels from the left and right sides  
>>>> of the original image.
>>>>
>>>> At least, that's my take on things. We'll see what others say  
>>>> (though they've tended to ignore Python questions in the past).
>>>>
>>>> Incidentally, the subject line says "Core Image resize question."  
>>>> The code below has no reference to Core Image, and I'm pretty  
>>>> sure that Core Image need not be involved in this task at all.  
>>>> (Perhaps you mentioned Core Image because of the existence of its  
>>>> CICrop filter, but I think that's not the best direction for the  
>>>> task at hand.)
>>>>
>>>> --Glenn
>>>>
>>>>
>>>> On Aug 11, 2008, at 5:33 AM, Adam Jones wrote:
>>>>
>>>> Hi there i am wondering if someone can help me with this. Below  
>>>> is the code i am using to resize and save a jpeg image.
>>>>
>>>> It works mint as but it obviously scales the image with no  
>>>> respect for the aspect ratio.
>>>>
>>>> i want to be able to take an image and scale it proportionaly to  
>>>> a square thumbnail. so for example a 800x600 image scaled to  
>>>> 80x80 would need to loose 100pixels off the left and 100 pixels  
>>>> on the right before scaling.
>>>>
>>>> Does any one know how to crop using python quartz or can i draw  
>>>> the rec with the image off the canvas to achieve the same?
>>>>
>>>> Thanks Adam
>>>>
>>>>
>>>> ----------- #!/usr/bin/python
>>>>
>>>> import CoreGraphics
>>>>
>>>> def resizeimage(srcimage,targetimage, w, h):
>>>>
>>>> origImage = CoreGraphics .CGImageImport  
>>>> (CoreGraphics.CGDataProviderCreateWithFilename(srcimage))
>>>>
>>>> origwidth = origImage.getWidth() # not used yet but will be once  
>>>> i work out how to crop
>>>> origheight = origImage.getHeight() # not used yet but will be  
>>>> once i work out how to crop
>>>>
>>>> cs = CoreGraphics.CGColorSpaceCreateDeviceRGB()
>>>> c = CoreGraphics.CGBitmapContextCreateWithColor(w, h, cs,  
>>>> (0,0,0,0))
>>>>
>>>> c.setInterpolationQuality(CoreGraphics.kCGInterpolationLow)
>>>> newRect = CoreGraphics.CGRectMake(0, 0, w, h)
>>>> c.drawImage(newRect, origImage)
>>>> c.writeToFile(targetimage, CoreGraphics.kCGImageFormatJPEG)
>>>>
>>>>
>>>> resizeimage(uploadedfile, "/svr/data/images/listings/%s/  
>>>> %s_160x90.jpg" % (str(listing_id), newimagename), 160,90)
>>>>
>>>> -------------
>>>>
>>>>
>>>> _______________________________________________ Do not post admin  
>>>> requests to the list. They will be ignored. Quartz-dev mailing  
>>>> list (email at hidden) Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/quartz-dev/email@hidden
>>>>
>>>> This email sent to email at hidden
>>>
>
>
>
>
>
>
>
>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/image-sig/attachments/20090603/a0441473/attachment-0001.htm>


More information about the Image-SIG mailing list