Modifying of postscript layers separately after input

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
emil
Posts: 2
Joined: 2012-03-30T09:30:03-07:00
Authentication code: 8675308

Modifying of postscript layers separately after input

Post by emil »

I'm stumped (after many successful years of using IM!)
(infile.ps contains one or two separate layers)

Code: Select all

convert infile.ps outfile.jpg
correctly produces> outfile-0.jpg and outfile-1.jpg

The problem is that I want to modify the two layers/images differently before I output them.

This is a pseudo example where "settingX" is the setting I don't know! that sets the currently active image/layer)

Code: Select all

convert infile.ps (-settingX 0 -rotate 90) (-settingX 1 -rotate 270) outfile.jpg
What should "settingX" be?

ps:
The following command kinda works, but is 2x slower in performance and duplicates layer 0 as false layer 1 if layer 1 doesn't exist in the infile.ps. My guess is because it calls GhostScript two separate times:

Code: Select all

convert ( infile.ps[0] -rotate 90 ) tag.ps[1] outfile.jpg
pps: I can get this to work with a script that outputs the multiple jpgs and then reads them back in separately and resaves them again. This is very slow since it's disk intensive and this is a live web-app that I'm working on. (in theory: 2 seconds vs 10 seconds)

Version: ImageMagick 6.6.7-9 2011-02-21 Q16
Windows XP
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Modifying of postscript layers separately after input

Post by fmw42 »

convert infile.ps (-settingX 0 -rotate 90) (-settingX 1 -rotate 270) outfile.jpg
try


convert infile.ps ( -clone 0 -rotate 90 ) ( -clone 1 -rotate 270 ) -delete 0,1 outfile.jpg

Be sure you have spaces between the parens and the commands inside them
emil
Posts: 2
Joined: 2012-03-30T09:30:03-07:00
Authentication code: 8675308

Re: Modifying of postscript layers separately after input

Post by emil »

fmw42 wrote:
convert infile.ps (-settingX 0 -rotate 90) (-settingX 1 -rotate 270) outfile.jpg
try


convert infile.ps ( -clone 0 -rotate 90 ) ( -clone 1 -rotate 270 ) -delete 0,1 outfile.jpg

Be sure you have spaces between the parens and the commands inside them
Bingo! Thank You Fred!
It worked. (I was close to your solution at one point but I used: -delete 0 -delete 1 which isn't the same... I now realize)

It's a shame to do all that -cloning and -deleting when a "-selectlayer index" command would do the trick faster and cleaner.
ie.

convert infile.ps ( -selectlayer 0 -rotate 90 ) ( -selectlayer 1 -rotate 270 ) outfile.jpg
(warning to others the above line is wish-code and won't work!)
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Modifying of postscript layers separately after input

Post by fmw42 »

It's a shame to do all that -cloning and -deleting when a "-selectlayer index" command would do the trick faster and cleaner.
ie.

convert infile.ps ( -selectlayer 0 -rotate 90 ) ( -selectlayer 1 -rotate 270 ) outfile.jpg
(warning to others the above line is wish-code and won't work!)
That is basically what -clone is doing. It does not re-read the image, only the metadata as I understand it and then references back to the right "layer". IM sees a multilayer image as a sequence of images once they are read in. So when you read it in, it sees effectively two images, one for each layer. The -clone #, then selects that image which is already in memory. So it is really fast.

I think you could do

convert \( infile.ps[0] -rotate 90 ) ( infile.ps[1] -rotate 270 ) outfile.jpg

But then you might be reading in both layers twice. I am not sure about this, though. If you remove the parens, I am not sure, also, if the second image will see both rotates. Anthony can clarify, if I am wrong. Or you can just try some tests to see what happens and which is faster.
Post Reply