Page 1 of 1

How can I combine these two commandlines?

Posted: 2011-03-31T16:23:28-07:00
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.

Re: How can I combine these two commandlines?

Posted: 2011-03-31T17:26:57-07:00
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

Re: How can I combine these two commandlines?

Posted: 2011-03-31T17:39:34-07:00
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.

Re: How can I combine these two commandlines?

Posted: 2011-03-31T20:14:12-07:00
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.

Re: How can I combine these two commandlines?

Posted: 2011-03-31T20:16:25-07:00
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?