Preserving layers for EPS or SVG output

IMagick is a native PHP extension to create and modify images using the ImageMagick API. ImageMagick Studio LLC did not write nor does it maintain the IMagick extension, however, IMagick users are welcome to discuss the extension here.
Post Reply
colindean

Preserving layers for EPS or SVG output

Post by colindean »

I'm attempting to assemble a script which takes multiple images and/or text and combines them into a single, layered vector image. The source images are JPG, GIF, PNG, or EPS. I would prefer that the output be EPS, but it could be SVG if ImageMagick's support for it produces sufficient output.

I've pretty much learned how to adjust the individual images/layers to correct color or remove backgrounds, etc., but I'm failing to understand how to output the adjusted images together in one, layered image.

Here's what I'm doing so far. I'd post code, but I've mangled it a little and it's not currently producing anything, although this process is the general process I see in my mind.

I create a blank 750x750 Imagick image and set its background to white. This is essentially the container image.

I create an instance of Imagick for each component image, and do whatever I need to do to prepare that image/layer. There could be any number of these, but probably not more than two or three. That doesn't really matter, though, as each should be on a separate layer and still be vector if the source image was vector, embedded/raster if the source was raster.

For any text layers, I create essentially a duplicate of the container layer and set its background to transparent (create it with a green background, then use

Code: Select all

$im->paintTransparentImage(new ImagickPixel("green"), 0.0, 0);
to make it transparent). I annotate or whatever and continue. I haven't worked much on this step at all yet since I figure it's irrelevant to the problem at hand.

I then create a new, final Imagick instance, then ::addImage() each image/layer.

I tried simply outputting this, and it simply outputs the last image added as an EPS.

I also tried methods such as ::coalesceImage() and ::combineImage(), to no avail. I also tried ::getImagesBlob(), but it failed to produce any output at all.

I also tried compositing each image onto the container, but the output of that was an EPS with an embedded, rasterized version of the image, which is useless.

So, I guess my question is this: How can I produce layered, vector output?

I'll continue banging away at this tomorrow when I return to work, but hopefully one of y'all can point me in the correct direction, or tell me that my goal is unattainable with Imagick.
colindean

Re: Preserving layers for EPS or SVG output

Post by colindean »

Scratch that.

I found the note on the ImageMagick site indicating that Imagemagick, and therefore Imagick, does not handle EPS vector output. It can do SVG output, but not of the quality I need SINCE...

...it also appears that vector clipart images we have were drawn using ONLY filled objects, no strokes. I can't think of an easy (< 1 week's work) way to programmatically find the outermost layers, do collision detection, and difference the top, white layers onto the background, colored layers and get a result which is just the colored outline of the clipart. I'm going to leave that to the artists and their arcane instruments ;-)
Post Reply