Difference between revisions of "Imagemagick Batch Processing"

From Tomelec
Jump to: navigation, search
(Shellscript batch processing)
(Shellscript batch processing)
Line 11: Line 11:
 
This cuts out the upper left 6x17 pixels. '''+0+0''' adjusts the offset. Use '''-depth 8''' to get 8bit PNGs instead of 16bit.
 
This cuts out the upper left 6x17 pixels. '''+0+0''' adjusts the offset. Use '''-depth 8''' to get 8bit PNGs instead of 16bit.
 
  <nowiki>for file in ../my_pngs/*.png; do echo $file; convert $file -crop 6x17+0+0! -depth 8 `basename $file`; done</nowiki>
 
  <nowiki>for file in ../my_pngs/*.png; do echo $file; convert $file -crop 6x17+0+0! -depth 8 `basename $file`; done</nowiki>
... can of course be combined with '''-scale''', here with different parameters:
+
... can of course be combined with '''-scale''', here with different parameters. '''!''' ignores the aspect ratio and ensures that the output images have the exact resolution given:
 
  <nowiki>for file in ../my_pngs/*.png; do echo $file; convert $file -crop 90x45+0+13 -scale 72x36! -depth 8 `basename $file`; done</nowiki>
 
  <nowiki>for file in ../my_pngs/*.png; do echo $file; convert $file -crop 90x45+0+13 -scale 72x36! -depth 8 `basename $file`; done</nowiki>
 +
 +
==Fade in/out==
 +
A fade in and out effect for PNG sequences, easily done with '''-modulate''':
 +
<nowiki># Fade in, 60 frames:
 +
i=0; for file in ../my_pngs/*.png; do echo $file; convert $file -modulate $(( ( $i * 100 ) / 60 )) -depth 8 $file; i=$(($i + 1)); done
 +
 +
#Fade out, 60 frames:
 +
i=60; for file in ../my_pngs/*.png; do echo $file; convert $file -modulate $(( ( $i * 100 ) / 60 )) -depth 8 $file; i=$(($i - 1)); done</nowiki>
 +
'''Attention:''' These examples overwrite the original files.

Revision as of 11:46, 2 September 2013

Imagemagick provides powerful tools for image manipulation. These can be easily automated in small shell scripts or command lines.

Shellscript batch processing

The following examples use basename $file to not overwrite the original file. Replace it by $file to overwrite the original.

Scale a bunch of photos

This scales all .JPG files in the directory ../mypics to 2048x1536 pixels. Note that the file extension (.JPG) is case sensitive and will not match .jpg files. The aspect ratio is preserved.

for file in ../mypics/*.JPG; do echo $file; convert "$file" -scale 2048x1536 -quality 85 `basename "$file"`; done

Crop out a section of PNG files

This cuts out the upper left 6x17 pixels. +0+0 adjusts the offset. Use -depth 8 to get 8bit PNGs instead of 16bit.

for file in ../my_pngs/*.png; do echo $file; convert $file -crop 6x17+0+0! -depth 8 `basename $file`; done

... can of course be combined with -scale, here with different parameters. ! ignores the aspect ratio and ensures that the output images have the exact resolution given:

for file in ../my_pngs/*.png; do echo $file; convert $file -crop 90x45+0+13 -scale 72x36! -depth 8 `basename $file`; done

Fade in/out

A fade in and out effect for PNG sequences, easily done with -modulate:

# Fade in, 60 frames:
i=0; for file in ../my_pngs/*.png; do echo $file; convert $file -modulate $(( ( $i * 100 ) / 60 )) -depth 8 $file; i=$(($i + 1)); done

#Fade out, 60 frames:
i=60; for file in ../my_pngs/*.png; do echo $file; convert $file -modulate $(( ( $i * 100 ) / 60 )) -depth 8 $file; i=$(($i - 1)); done

Attention: These examples overwrite the original files.