Page 1 of 1

Switching input file mid command

Posted: 2011-01-28T09:31:10-07:00
by btate
I'm working on a site that is forced to use a media conversion server. That server lets me issue the imagemagick parameters, but not the actual convert command, so multiple commands are out.

I have an image that I need resized, then I need that resized image cropped twice. I need all three resulting images saved separately.

Doing multiple calls to the conversion server will mean I basically have to develop a communication system between all the requests, so that I know when to do the next step, since the server uses callback urls and I don't have control over the info it sends back.

I've been playing around with something like this,
convert ./image.png -resize 160x320 -write ./image-resize.png -crop 50x50+15+15 -write ./image-cropped-1.png -crop 25x25+10+10 ./image-cropped-2.png

But the second crop will crop the result of the first crop. Is there way to do two different crops on the resized image in the same command?

Thanks,
Brandon

Re: Switching input file mid command

Posted: 2011-01-28T09:59:20-07:00
by Bonzo
This is probably what you are looking for there are other methods that you can use - some php examples on my site:
http://www.rubblewebs.co.uk/imagemagick ... o_temp.php

Code: Select all

input.png -resize 160x320 -write mpr:image +delete \( mpr:image -crop 50x50+15+15 -write image-cropped-1.png  \) \( mpr:image -crop 25x25+10+10 -write image-cropped-2.png \)

Re: Switching input file mid command

Posted: 2011-01-28T10:19:56-07:00
by btate
What is that mpr:image

Re: Switching input file mid command

Posted: 2011-01-28T10:29:50-07:00
by btate
I ended up doing this, because I need to base the crops off the result from the resize. Seems to work,

Code: Select all

convert ./image.png -resize 160x320 -write ./image-resize.png -crop 100x100+15+15 -write ./image-cropped-1.png +delete ./image-resize.png -crop 50x50+10+10 ./image-cropped-2.png

Re: Switching input file mid command

Posted: 2011-01-28T10:45:14-07:00
by Bonzo
The mpr: is writing the image to memory.

So the comand I posted resizes the original image and saves it to memory; it then takes the image in memory and crops it - saves the crop then recalls the image from memory and crops that and saves it.

As I said there are different methods to acheve the same result; you have one tempory image that needs clearing up and I do not - unless you wanted the original resized image as well.

Re: Switching input file mid command

Posted: 2011-01-28T10:50:38-07:00
by btate
That makes sense. I do need the original resized image, so I guess I have to go that route. But that memory command could definitely come in handy down the road. Thanks a lot. Saved me quite a bit of misery.

Re: Switching input file mid command

Posted: 2011-01-28T14:30:35-07:00
by fmw42
see clone and parenthesis processing

convert \( someimage command -write someoutput \) \
\( previous-someoutput command -write new-someoutput \)
etc


http://www.imagemagick.org/Usage/basics/#image_seq