Creating several images in one go.

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
RQuadling
Posts: 38
Joined: 2006-12-04T02:48:33-07:00
Location: Plymouth, Devon, UK
Contact:

Creating several images in one go.

Post by RQuadling »

Hello.

I am processing a LOT of images (several thousand a day). One of the tasks is to produce a scaled version of the image at different sizes (300x300, 150x150, 100x100, 60x60).

Initially I was doing something like this ...

Code: Select all

convert '/prod/891_original.jpg' -resize 300x300 '/prod/891_large.jpg'
convert '/prod/891_original.jpg' -resize 150x150 '/prod/891_medium.jpg'
convert '/prod/891_original.jpg' -resize 100x100 '/prod/891_small.jpg'
convert '/prod/891_original.jpg' -resize 60x60 '/prod/891_tiny.jpg'
But I found the -write option and ended up with ...

Code: Select all

convert '/prod/891_original.jpg' -resize 300x300 +write '/prod/891_large.jpg' -resize 150x150 +write '/prod/891_medium.jpg' -resize 100x100 +write '/prod/891_small.jpg' -resize 60x60 +write '/prod/891_tiny.jpg'
But this is generating an error which I do not understand how to fix ...

Code: Select all

convert: option requires an argument `+write' @ error/convert.c/ConvertImageCommand/2996.
The method nearly works correctly. The output is identical except that the last image is not produced.

Any suggestions?
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: Creating several images in one go.

Post by Bonzo »

This might be quicker:

Code: Select all

convert input.jpg \( +clone -thumbnail 300x300 -write 300.jpg +delete \) //
 \( +clone -thumbnail 150x150 -write 150.jpg +delete \) //
 \( +clone -thumbnail 100x100 -write 100.jpg +delete \) -thumbnail 60x60 60.jpg ");
or

Code: Select all

input.jpg -write mpr:image +delete //
 \( mpr:image -thumbnail 300x300 -write 300.jpg \) // 
 \( mpr:image -thumbnail 150x150 -write 150.jpg \) // 
 \( mpr:image -thumbnail 100x100 -write 100.jpg \) // 
 \( mpr:image -thumbnail 60x60 -write 60.jpg \)
 
RQuadling
Posts: 38
Joined: 2006-12-04T02:48:33-07:00
Location: Plymouth, Devon, UK
Contact:

Re: Creating several images in one go.

Post by RQuadling »

I'll give that a go.

If possible, can you tell me what I am/was doing wrong?
RQuadling
Posts: 38
Joined: 2006-12-04T02:48:33-07:00
Location: Plymouth, Devon, UK
Contact:

Re: Creating several images in one go.

Post by RQuadling »

Bonzo wrote:This might be quicker:

Code: Select all

convert input.jpg \( +clone -thumbnail 300x300 -write 300.jpg +delete \) //
 \( +clone -thumbnail 150x150 -write 150.jpg +delete \) //
 \( +clone -thumbnail 100x100 -write 100.jpg +delete \) -thumbnail 60x60 60.jpg ");
or

Code: Select all

input.jpg -write mpr:image +delete //
 \( mpr:image -thumbnail 300x300 -write 300.jpg \) // 
 \( mpr:image -thumbnail 150x150 -write 150.jpg \) // 
 \( mpr:image -thumbnail 100x100 -write 100.jpg \) // 
 \( mpr:image -thumbnail 60x60 -write 60.jpg \)
 
Using the last example, I get errors ...

Code: Select all

[Fri Mar 30 11:18:14] [/development/_images/prod/1275/2002926] $ convert orig.jpg -write mpr:image +delete \
> \( mpr:image -thumbnail 300x300 -write 300t.jpg \) \
> \( mpr:image -thumbnail 150x150 -write 150t.jpg \) \
> \( mpr:image -thumbnail 100x100 -write 100t.jpg \) \
> \( mpr:image -thumbnail 60x60 -write 60t.jpg \)
convert: unbalanced parenthesis `)' @ error/convert.c/ConvertImageCommand/3012.
The thumbnails are produced. I need to have a clean output (except for real errors) as this is unattended system and only real errors need to be logged.
RQuadling
Posts: 38
Joined: 2006-12-04T02:48:33-07:00
Location: Plymouth, Devon, UK
Contact:

Re: Creating several images in one go.

Post by RQuadling »

Same with

Code: Select all

convert orig.jpg \( +clone -thumbnail 300x300 -write 300t.jpg +delete \) \( +clone -thumbnail 150x150 -write 150t.jpg +delete \) \( +clone -thumbnail 100x100 -write 100t.jpg +delete \) \( +clone -thumbnail 60x60 -write 60t.jpg +delete \)
outputs

Code: Select all

convert: unbalanced parenthesis `)' @ error/convert.c/ConvertImageCommand/3012.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Creating several images in one go.

Post by fmw42 »

convert orig.jpg \( +clone -thumbnail 300x300 -write 300t.jpg +delete \) \( +clone -thumbnail 150x150 -write 150t.jpg +delete \) \( +clone -thumbnail 100x100 -write 100t.jpg +delete \) \( +clone -thumbnail 60x60 -write 60t.jpg +delete \)
Mainly, add null: to the end. Also change +clone to -clone 0 so you are not processing the previous jpg successively and thus getting more compression and loss of quality each time.

convert orig.jpg \
\( -clone 0 -thumbnail 300x300 -write 300t.jpg +delete \) \
\( -clone 0 -thumbnail 150x150 -write 150t.jpg +delete \) \
\( -clone 0 -thumbnail 100x100 -write 100t.jpg +delete \) \
\( -clone 0 -thumbnail 60x60 -write 60t.jpg +delete \) \
null:

This works for me.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Creating several images in one go.

Post by anthony »

RQuadling wrote: But I found the -write option and ended up with ...

Code: Select all

convert '/prod/891_original.jpg' -resize 300x300 +write '/prod/891_large.jpg' -resize 150x150 +write '/prod/891_medium.jpg' -resize 100x100 +write '/prod/891_small.jpg' -resize 60x60 +write '/prod/891_tiny.jpg'
But this is generating an error which I do not understand how to fix ...

Code: Select all

convert: option requires an argument `+write' @ error/convert.c/ConvertImageCommand/2996.
"convert" command assumes the last argument is a 'implied write' as such that final -write does not in fact have an argument (its filename is already taken by the 'implied write') so it produces an error about not having an argument.

If you want to keep things the same for all the images append a final 'null:' for the 'implied write'

ASIDE: I recomment you break up your command with multiple lines to make it look neater.
Using '\' on end of lines for UNIX shell, '^' and indent for DOS, and '.' string concatenation for PHP. See respective tutorials for those languages
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
RQuadling
Posts: 38
Joined: 2006-12-04T02:48:33-07:00
Location: Plymouth, Devon, UK
Contact:

Re: Creating several images in one go.

Post by RQuadling »

Thanks again.
Post Reply