read image once, but save 3 versions

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
jaffamuffin
Posts: 59
Joined: 2009-01-30T03:46:08-07:00

read image once, but save 3 versions

Post by jaffamuffin »

Hi All

I come accross this problem in various places, so hopefully I can get an answer on how to do this that I can apply in various ways.

This particular problem, I'm converting some images to binary, but sometimes I need to go back and redo one if it didn't convert well enough using a different setting. I'd like to just process 3 different versions of the image to start with. I would like to read in the image once, but output 3 copies with different processing. How do I do that the quickest way?

My command is (i've edited as it normally runs in a loop) :

Code: Select all

convert sample.jpg !lat! ^
                    -background white -gravity center -extent 3307x4667 ^
                    -compress group4 -define quantum:polarity=min-is-white version1\out.tif
Where !lat! would be the following:

Code: Select all

-lat 85x85-30
-lat 85x85-10
-lat 50x50-40

Ideally the outfiles would drop into 3 parallel directory trees. (rather than the same dir)

Anybody able to help ?

(PS is that a good way to convert greyscale scanned text to binary ? )
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: read image once, but save 3 versions

Post by fmw42 »

What is your IM version and platform? Syntax is different for Windows and Unix.

In Unix syntax:

Code: Select all

convert image \
\( -clone 0  ...yourprocessing1... +write path1/result1 \) \
\( -clone 0  ...yourprocessing2... +write path2/result2 \) \
\( -clone 0  ...yourprocessing3... +write path3/result3 \) \
null:


Windows syntax

Code: Select all

convert image ^
( -clone 0  ...yourprocessing1... +write path1/result1 ) ^
( -clone 0  ...yourprocessing2... +write path2/result2 ) ^
( -clone 0  ...yourprocessing3... +write path3/result3 ) ^
null:
See
http://www.imagemagick.org/Usage/basics/#parenthesis
http://www.imagemagick.org/Usage/files/#write
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: read image once, but save 3 versions

Post by snibgo »

As Fred says. Each "-clone" creates a copy in memory, which is processed then written to a file. When it is no longer needed, it can be deleted from memory. This reduces the memory requirements of the command. Windows BAT syntax:

Code: Select all

convert image ^
( -clone 0  ...yourprocessing1... +write path1/result1 +delete ) ^
( -clone 0  ...yourprocessing2... +write path2/result2 +delete ) ^
( -clone 0  ...yourprocessing3... +write path3/result3 +delete ) ^
null:
snibgo's IM pages: im.snibgo.com
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: read image once, but save 3 versions

Post by fmw42 »

As snibgo has written +delete, that is probably more efficient, since it deletes the clone as soon as it is not needed. But since the formal output is null:, any image (clone) left around would be deleted at the end.
jaffamuffin
Posts: 59
Joined: 2009-01-30T03:46:08-07:00

Re: read image once, but save 3 versions

Post by jaffamuffin »

Thanks. That is exactly what was needed.
Post Reply