Switching input file mid command

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
btate
Posts: 4
Joined: 2011-01-28T09:23:23-07:00
Authentication code: 8675308

Switching input file mid command

Post 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
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: Switching input file mid command

Post 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 \)
btate
Posts: 4
Joined: 2011-01-28T09:23:23-07:00
Authentication code: 8675308

Re: Switching input file mid command

Post by btate »

What is that mpr:image
btate
Posts: 4
Joined: 2011-01-28T09:23:23-07:00
Authentication code: 8675308

Re: Switching input file mid command

Post 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
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: Switching input file mid command

Post 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.
btate
Posts: 4
Joined: 2011-01-28T09:23:23-07:00
Authentication code: 8675308

Re: Switching input file mid command

Post 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.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Switching input file mid command

Post 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
Post Reply