How can I combine these two commandlines?

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
regz
Posts: 2
Joined: 2011-03-31T16:03:10-07:00
Authentication code: 8675308

How can I combine these two commandlines?

Post by regz »

How can I perform these two example commands as one command?

Code: Select all

convert input.jpg -strip -colorspace Gray -filter Lanczos -resize 800 -unsharp 1.1x1.0+1.0+0.05 step1.jpg
convert -size W1xH1 -depth 8 canvas: \
    (step1.jpg -crop W2xH2+X1+Y1 ) -geometry +X2+Y2 -composite \
    (step1.jpg -crop W2xH2+X3+Y3 ) -geometry +X4+Y4 -composite \
    ...etc... \
    -quality 92 output.jpg
In my current method I just put the command from step1 into the parenthesis of step2, but it think i'm doing a lot of extra work like that.

This is my first time using IM. I read the manual and I tried a couple dozen variations with -clone and similar commands but I can't figure it out.

Incidentally, my final output is destined for an e-ink screen (Kindle K3, 167ppi) so any tips/filters to improve contrast (like unsharp) would be helpful.

Please help,
thank you.
el_supremo
Posts: 1015
Joined: 2005-03-21T21:16:57-07:00

Re: How can I combine these two commandlines?

Post by el_supremo »

I can't try this out but see if this does what you want:
EDITED: to add space after each left parenthesis and add -wite (thanks Fred).

Code: Select all

convert ( input.jpg -strip -colorspace Gray -filter Lanczos -resize 800 -unsharp 1.1x1.0+1.0+0.05 -write mpr:a ) +delete \
	-size W1xH1 -depth 8 canvas: \
    ( mpr:a -crop W2xH2+X1+Y1 ) -geometry +X2+Y2 -composite \
    ( mpr:a -crop W2xH2+X3+Y3 ) -geometry +X4+Y4 -composite \
    ...etc... \
    -quality 92 output.jpg
This writes the step1.jpg image into a Memory Program Register. The first set of parentheses may not be required but won't hurt.

Pete
Last edited by el_supremo on 2011-03-31T18:01:53-07:00, edited 3 times in total.
Sorry, my ISP shutdown all personal webspace so my MagickWand Examples in C is offline.
See my message in this topic for a link to a zip of all the files.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: How can I combine these two commandlines?

Post by fmw42 »

I cannot tell whether you are on windows are unix as you have mixed syntax. On unix, parens need escaping by \ and lines are continued with \. On windows the parens don't need escaping and the line continuations are set by ^. So the following assumes you are windows, though I am better with unix syntax.

try using in memory images mpr: to avoid potential problems with nested parens with -clone and -crop (needed since one cannot delete the first image until the end with clones, whereas with mpr, it can be deleted right away). Most of the time clones works just fine and is easy. This case is a bit complicated and so it seemed to me that mpr might be simpler.

convert ( input.jpg -strip -colorspace Gray -filter Lanczos -resize 800 -unsharp 1.1x1.0+1.0+0.05 -write mpr:tmp +delete ) ^
-size W1xH1 -depth 8 canvas:white ( mpr:tmp -crop W2xH2+X1+Y1 +repage ) -geometry +X2+Y2 -composite ^
( mpr:tmp -crop W2xH2+X3+Y3 +repage ) -geometry +X4+Y4 -composite -quality 92 output.jpg

or use -flatten which is cleaner and simpler when multiple images are to be composited
also you can remove the crop to make it easier

Window:
convert ( input.jpg -strip -colorspace Gray -filter Lanczos -resize 800 -unsharp 1.1x1.0+1.0+0.05 -write mpr:tmp +delete ) ^
-size W1xH1 -depth 8 canvas:white ^
-page +X2+Y2 mpr:tmp[W2xH2+X1+Y1] ^
-page +X4+Y4 mpr:tmp[W2xH2+X3+Y3] ^
-flatten -quality 92 output.jpg

Unix:
convert \( input.jpg -strip -colorspace Gray -filter Lanczos -resize 800 -unsharp 1.1x1.0+1.0+0.05 -write mpr:tmp +delete \) \
-size W1xH1 -depth 8 canvas:white \
-page +X2+Y2 mpr:tmp[W2xH2+X1+Y1] \
-page +X4+Y4 mpr:tmp[W2xH2+X3+Y3] \
-flatten -quality 92 output.jpg

see
http://www.imagemagick.org/Usage/layers/#flatten
http://www.imagemagick.org/Usage/files/#mpr

One would have to see your images and exact command line to advise further about quality.

Note the +repage after a crop to remove the virtual canvas, though this is not necessary for jpgs

Sorry I seemed to have posted just about the same time as el_supremo and we both have about the same solution.
regz
Posts: 2
Joined: 2011-03-31T16:03:10-07:00
Authentication code: 8675308

Re: How can I combine these two commandlines?

Post by regz »

Thanks guys, using in memory images did the trick.

-page/-flatten didn't quite work though, it produces a different output than substituting mpr into my more verbose command.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: How can I combine these two commandlines?

Post by fmw42 »

regz wrote:Thanks guys, using in memory images did the trick.

-page/-flatten didn't quite work though, it produces a different output than substituting mpr into my more verbose command.

What version of IM and what platform are you using?

Can you post a link to your input image and command line, so we can test why it did not work?
Post Reply