I have a source image (say 1600x1200) for which I want to create a series of thumbnails with different resolutions:
- 900x0 (i.e. means that the image is scaled in proportion to the width of 900 px).
- 700x0
- 0x550 (i.e. means that the image is scaled proportionally to 550 pixels in height)
- 0x400
- 0x150
- 200x200 (i.e. cropped and centered)
Individually, I can process each of these transformations with a team convert. The problem is that it is a huge waste of resources for constant reinitialization convert; it would be better to put things together so that they convertcan reuse their work.
Using ImageMagick 6.7.0-10 I tried the following (using the parameter +write, see http://www.imagemagick.org/script/command-line-options.php#write ), but it does not work, because the command +writeis ineffective in restoring images in initial state:
convert '/tmp/original.jpg'[0] -quality 95 -density 72x72 -resample 72x72 +profile '!xmp,*' -resize '900>' +write '/tmp/900.jpg' -resize '700>' +write '/tmp/700.jpg' -resize '200x' -crop '200x200+0+35' +repage +write '/tmp/200.jpg' -resize 'x550>' +write '/tmp/550.jpg' -resize 'x400>' +write '/tmp/400.jpg' -resize 'x150>' '/tmp/150.jpg'
As an alternative, I tried the following (using +cloneand -delete). It seems to work, but it could probably be more efficient (perhaps from mpr:, http://www.imagemagick.org/Usage/files/#mpr ):
convert 'original.jpg'[0] -quality 95 -density 72x72 -resample 72x72 +profile '!xmp,*' \( +clone -resize 'x150>' -write '150.jpg' \) -delete 1 \( +clone -resize 'x400>' -write '400.jpg' \) -delete 1 \( +clone -resize 'x550>' -write '550.jpg' \) -delete 1 \( +clone -resize '200x' -crop '200x200+0+35' +repage -write '200.jpg' \) -delete 1 \( +clone -resize '700>' -write '700.jpg' \) -delete 1 -resize '900>' '900.jpg'
Can someone explain what I am doing wrong in the first example (using the command +write)? Also, can anyone suggest any improvements to improve processor / memory performance?
EDIT
Here's an improvement using mpr:
convert 'original.jpg'[0] -quality 95 -density 72x72 -resample 72x72 +profile '!xmp,*' -write mpr:orig +delete mpr:orig -resize 'x150>' -write '150.jpg' +delete mpr:orig -resize 'x400>' -write '400.jpg' +delete mpr:orig -resize 'x550>' -write '550.jpg' +delete mpr:orig -resize '200x' -crop '200x200+0+35' +repage -write '200.jpg' +delete mpr:orig -resize '700>' -write '700.jpg' +delete mpr:orig -resize '900>' '900.jpg'
, +write .