Page 1 of 1

Creating several images in one go.

Posted: 2012-03-30T01:29:03-07:00
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?

Re: Creating several images in one go.

Posted: 2012-03-30T02:33:49-07:00
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 \)
 

Re: Creating several images in one go.

Posted: 2012-03-30T02:36:55-07:00
by RQuadling
I'll give that a go.

If possible, can you tell me what I am/was doing wrong?

Re: Creating several images in one go.

Posted: 2012-03-30T03:20:01-07:00
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.

Re: Creating several images in one go.

Posted: 2012-03-30T03:25:56-07:00
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.

Re: Creating several images in one go.

Posted: 2012-03-30T09:15:05-07:00
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.

Re: Creating several images in one go.

Posted: 2012-03-30T17:38:39-07:00
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

Re: Creating several images in one go.

Posted: 2012-03-30T23:24:29-07:00
by RQuadling
Thanks again.