tags:

views:

81

answers:

2

If you Save as > jpg in Adobe Photoshop a path (selection) is stored in the file.
Is it possible to read that path in python, for example to create a composition with PIL?

EDIT
Imagemagick seems to help, example

A: 

Are you sure the path is stored in the jpg? That seems unlikely. Paths would be stored in native photoshop format, but not the jpg.

Do you know of any other tools that can read the path? Can you try saving the item as a jpg, close photoshop, reopen only the jpg and see if you still have the path? I doubt it'd be there.

Parand
Yes, its still there in Photoshop. If you Save as(not Save for web) the path gets saved in the .jpg. We use this when we distribute high res images with path for quick selection. Dont know if GIMP or other code can read it.
amoeba
+1  A: 

This code (by /F AKA the effbot, author of PIL and generally wondrous Python contributor) shows how to walk through the 8BIM resource blocks (but it's looking for 0x0404, the IPTC/NAA data, so of course you'll need to edit it).

Per Tom Ruark's post to this thread, paths will have IDs of 2000 to 2999 (the latter gives the name of the clipping path, so it's different from the others) and the data's a series of 26-bytes "point records" (so the resource length is always a multiple of 26).

Read the rest in Tom's post in all the gory details -- it's a pesky and very detailed binary format that will take substantial experimentation (and skill with struct, bitwise manipulation, etc) to read and interpret just right (not helped by the fact that the fields can be big-endian or little-endian -- little-endian in Windows, if I read the post correctly).

Alex Martelli
I rest my case, harcore programmer needed :)
amoeba
@amoeba, I entirely agree. If I was given this task at work I would estimate (given a bunch of JPGs covering all cases my code must deal with) 2-3 days' work (for production code including testing and docs), and I tend to be a pretty fast programmer (and optimistic in my estimates -- just like everybody else in this regard of course;-).
Alex Martelli
@Alex Martelli, in my case being stubborn and give it try == failure. I prefer spending that time learning Imagemagick, thanks for directions!
amoeba