Techniques — Image processing
Back to techniques

Based on Ubuntu 10.04 (a variety of Debian Linux).

Shrink JPEGs

#Install imagemagick:
sudo apt-get install imagemagick

#Use a loop to convert:
for img in *.jpg; do convert "$img" -resize 600x600 "re_$img"; done


Other handy basic image manipulation examples

All using imagemagick:

# Compress a TIFF
convert -compress lzw source.tiff dest.tiff

# Show extended file image information
identify -verbose dest.tiff

# Convert a PDF to TIFF (600 dpi, 8 bpp, compressed)
convert -density 600 -depth 8 -compress lzw source.pdf dest.tiff

Batch process photos from an EXIF camera with rotation information

Download as photoprocess or see below:


# Requires package: jhead

jhead -ft -autorot -n%Y_%m_%d/photo_%Y_%m_%d_%H%M_%S *.JPG

# -ft		writes the EXIF date/time to the file date/time
# -autorot	autorotate the image to match the EXIF rotation info
# -nSPEC	renames the files

Batch rotate MPEGs

Download as mpegrotate or see below:


# Requires packages: mplayer mencoder

syntax="Syntax: mpegrotate [cw|ccw] inputfilename\n"
if [ $# -lt 2 ]; then
	echo $syntax
	exit 0

if [ "$1" == "cw" ]; then
elif [ "$1" == "ccw" ]; then
	echo $syntax
	exit 1

# For Bash scripting, see
# Now, if our script is called e.g. as "mpegrotate cw *.mpg", $2 will NOT contain "*.mpg"; it will contain the first element in the expansion of this (globbing happens before the script is called).
# So use $@ to represent all arguments instead.
# Or, to iterate over 2-n not 1-n, use the indirection syntax below:
# Or use shift:

for ((i=2; i<$#; i++))
	/usr/bin/mencoder -ovc lavc -vf rotate=$rotation -oac copy $infile -o $outfile
	# -ovc lavc = encode with a libavcodec codec
	# -oac copy = no audio encoding, just streamcopy
	# -vf adds video filters:
	# -vf rotate=
	#	0 Rotate by 90 degrees clockwise and flip (default).
	#	1 Rotate by 90 degrees clockwise.
	#	2 Rotate by 90 degrees counterclockwise.
	#	3 Rotate by 90 degrees counterclockwise and flip.

exit 0

Valid HTML 4.01 Transitional
Valid CSS