Techniques — Image processing
Back to techniques
https://rcardinal.ddns.net/techniques/image.html

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

#Links:
# http://www.imagemagick.org/script/co...line-tools.php
# http://www.imagemagick.org/script/convert.php

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:

#!/bin/sh

# 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:

#!/bin/bash

# Requires packages: mplayer mencoder

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

if [ "$1" == "cw" ]; then
	rotation=1
elif [ "$1" == "ccw" ]; then
	rotation=2
else
	echo $syntax
	exit 1
fi

# For Bash scripting, see http://tldp.org/LDP/abs/html/
# 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: http://stackoverflow.com/questions/1769140/how-to-iterate-over-positional-parameters-in-a-bash-script
# Or use shift: http://tldp.org/LDP/abs/html/othertypesv.html#EX19

for ((i=2; i<$#; i++))
do
	infile=${!i}
	outfile=$infile$rotatedsuffix
	/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.
done

exit 0

Valid HTML 4.01 Transitional
Valid CSS