Page 1 of 1

getting work+clipping paths from Photoshop-generated files?

Posted: 2008-04-02T14:41:02-07:00
by hhas
I'm looking to extract a list of work and clipping paths from Photoshop CS3 generated PSD, TIF, etc. files. So far I'm getting a list of basic image properties, but not those in the 8BIM resource - anyone know why?

Here's the code:

Code: Select all

#include <stdio.h>
#include <stdlib.h>
#include <wand/MagickWand.h>

int main(int argc,char **argv)
{
	MagickBooleanType status;
	MagickWand *w;
	unsigned long n;
	char **props, *val;
	char *pattern = "*";
	int i;

	if (argc != 2) exit(1);

	MagickWandGenesis();
	w = NewMagickWand();  
	status = MagickReadImage(w, argv[1]);
	if (status == MagickFalse) exit(1);

	MagickResetIterator(w);
	while (MagickNextImage(w) != MagickFalse) {
		
		// list properties for image
		printf("IMAGE:\n");
		props = MagickGetImageProperties(w, pattern, &n);
		for (i = 0; i < n; i++) {
			val = MagickGetImageProperty(w, props[i]);
			printf("  %20s = %s\n", props[i], val);
			MagickRelinquishMemory(val);
		}
		MagickRelinquishMemory(props);
	}
	
	DestroyMagickWand(w);
	MagickWandTerminus();
	return 0;
}
Example output:

Code: Select all

IMAGE:
           create-date = 2008-04-02T19:02:34+01:00
           modify-date = 2008-04-02T19:02:34+01:00
IMAGE:
           create-date = 2008-04-02T19:02:34+01:00
                 label = Lager 1
           modify-date = 2008-04-02T19:02:34+01:00
Digging further into the IM source, I found that I could get the first path in the file as follows:

Code: Select all

val = MagickGetImageProperty(w, "8BIM:1998,2998");
printf("  %20s = %s\n", val);
MagickRelinquishMemory(val);
which may or may not be the clipping path. [1]

Or I can get a path by name, e.g.:

Code: Select all

val = MagickGetImageProperty(w, "8BIM:1998,2998:Work path 1\n");
printf("  %20s = %s\n", val);
MagickRelinquishMemory(val);
What I can't see though is a way to get a list of all path names, plus an indication of which one is a clipping path (if any), so any advice here would be much appreciated.

...

To provide some background: I'm looking to convert CS3 PSD/TIF/etc. files to PDFs on OS X while allowing the user to specify a clipping path from the files' existing work/clipping paths. Unfortunately, the standard OS X APIs (Quartz, NSImage, etc.) appear to ignore Photoshop's work/clipping path info when importing the files, so the plan is to get that information separately and then use Quartz to apply the desired clipping path to the bitmap along with any other transformations specified by the user.

IM seems an obvious option for solving the first step (extracting path info), if only I can get it to work. Although if anyone knows of any other low-cost, standalone Tiger/Leopard-compatible solutions for part or all of this task, I'm all ears.

Many thanks,

has
--

[1] Side-note: I notice that using 'identify -verbose ...' in the shell lists the first path found as the clipping path, even if it's just a work path; I suspect this is a bug.

Re: getting work+clipping paths from Photoshop-generated files?

Posted: 2008-04-04T07:31:11-07:00
by NitroPye
What version of IM are you using? I was having an issue with CS3 generated files and clipping paths which the latest beta fixed.

Re: getting work+clipping paths from Photoshop-generated files?

Posted: 2008-04-05T09:55:00-07:00
by hhas
NitroPye wrote:What version of IM are you using? I was having an issue with CS3 generated files and clipping paths which the latest beta fixed.
ImageMagick 6.4.0 03/30/08 Q16

Which version are you on?

e.g. Running 'identify -verbose Original Photoshop file.psd' would list the first path in the file as a clipping path, whereas the first path is just an ordinary work path and the actual clipping path is third in the file.

Here's the test file if you want to try it yourself.

Many thanks.