&& The Linux Image Book
  -----------------------:

 This booklet is about using tools available on the Linux
 operating system for manipulating images. It is oriented towards
 using command-line programs rather than graphical tools such as
 'gimp'.

FINDING IMAGES

  * Find corrupted jpeg image files
  >> find . -name "*jpg" -exec jpeginfo -c {} \; | grep -E "WARNING|ERROR"

  * Determine an image's dimensions
  >> identify -format "%wx%h" /path/to/image.jpg

  * Convert images (jpg, png, ...) into a big PDF 'big.pdf'
  >> convert images*.* big.pdf

  * Scale, rotate, brightness, contrast,...with Image Magick
  >> convert -rotate $rotate -scale $Widthx$Height -modulate $brightness -contrast $contrast -colorize $red%,$green%,$blue% $filter file_in.png file_out.png

MANAGING IMAGES

  * find all image files in the 'icons' folder
  >> find /usr/share/icons/ | xargs file | grep image | less

  * find all image files on the computer
  >> sudo find / | xargs file | grep ' image' | less

  * display only the names of the image files in the icons folder
  >> find /usr/share/icons/ | xargs file | grep ' image' | cut -d: -f1 

  * view and manage all icon images with gthumb ???
  >> gthumb $(find /usr/share/icons/ | xargs file | grep ' image' | cut -d: -f1)
  The "grep ' image'" is needed since otherwise 'image' folders
  will be included in the search

VIEWING IMAGES

 @@ http://www.linux.org/apps/all/Graphics/Image_Viewing.html
    a list of all image viewers

  == linux image viewers
  .. xv - an old x windows viewer
  .. xli - another one
  .. aview - ascii image viewer
  .. asciiview - 
  .. feh - a fast command line driven image viewer
  .. gthumb - a gnome viewer and simple editor
  .. geeqie - gtk image viewer
  .. gpicview - small image viewer
  .. gqview - simple gtk image viewer, emacs style keys
  .. eye of gnome - the gnome viewer
  .. mirage - simple gtk viewer, with thumbnails
  .. imgseek - image viewer, manager, requires python
  .. pqiv - similar to qiv, but different, very basic
  .. qiv - quick image viewer, up to date
  .. gwenview - kde image viewer
  .. showfoto - kde
  ..

  * show jpegs with thumbnails
  >> find ~ -name '*.jpg' | xargs mirage 

FEH

  Feh is a fast command line driven image viewer. maybe
  just what we need.

  * show all the images in the /opt/images tree in  a slideshow.
  >> feh -r /opt/images

  * same again, but sort by image name before showing.
  >> feh -rSname /opt/image

  * create a montage from the images in /opt/images/landscapes
  >> feh -m /opt/images/landscapes

  * Create a montage from the images in /opt/images/landscapes and
  * all directories below it. Limit the width of the image to  400
  * and make the thumbnails 30x20, ignoring aspect ratio
  >> feh -Xrm -W 400 --thumb-width 30 --thumb-height 20 ./landscapes

  Feh is fast and flexible for managing images

  @@ http://www.linux.com/archive/feature/113978
     good image magick tips

  * view all photos in the 'photos' folder tree
  >> feh -r /usr/local/photos

  * view a 2 second delay slide show, random order, filenames from the file
  >> feh -D2 -z -f img.txt 

  * view an image from a url
  >> feh http://www.glerl.noaa.gov/pubs/photogallery/Scenic/images/0534.jpg
  
  * a random order slide show of images from urls, 30second delay
  >> cat image-urls | xargs feh -z -D30

  == feh keystrokes
  .. arrow keys - navigate through images
  .. space - next image
  .. backspace - back one
  .. control-del - delete the current file
  .. > - rotate the current image
  .. < - other rotations
  .. middle mouse button - zoom in
  .. left mouse button - pan around
  ,..
  ..

  * look at all images on the box, this is ok
  >> feh -r /

  * load all images, sort by size
  >> feh -S size -r /

  * display images and move the current image when the enter key is pressed
  >> feh -A "mv %f ~/images/%n" *

  >> sort:filename, width, height, pixels, size, format
  * create a thumbnail montage of everything in 'img' folder and display
  >> feh -m -r img/

  * create a thumbnail montage of everything in 'img' folder and save
  >> feh -m -O montage.png -r img/

  * create a random overlapping collage of images in the 'img' folder
  >> feh -c -O montage.png -r img/

  * create a montage with image information printed under each image
  >> feh -I -O montage.png -r img/

  * create a montage with image information using the 'courier' font
  >> feh -I -e courier -O montage.png -r img/

  * start feh in thumbnail mode, click each image to display fullsize
  >> feh -t -e courier -O montage.png -r img/

  * print image information about all jpeg images in the current folder
  >> feh -l *.png

  * print image information with a custom format
  >> feh -L ... -l *.png
  
EFFECTS ....

  * create a charcoal like drawing from a photo
  >> convert -charcoal 2 input.jpg output.jpg

  * create an even more 'charcoaly' image
  >> convert -charcoal 10 input.jpg output.jpg

  * make a very gaudy colourised version of a photo
  >> convert -colorize 255 input.jpg output.jpg

  * specify the red green blue to colorise
  >> convert -colorize 10/20/30 input.jpg output.jpg

  == other effects
  .. implode - swirls around the center
  .. solarize - like a nuclear exposure
  .. spread - random pixel fuzzyness
  ..

  * pixelize and image
  >> convert -sample 10% -sample 1000% input.jpg output.jpg

CREATING PAN ANIMATIONS 

  @@ kino - should be able to create pan & zoom 
  @@ stills2dv - cli for pan and zoom
  @@ 

EDUCATION

  @@ www.schoolforge.net
     educational software

3D IMAGES

  @@ art of illusion
     java based 3d rendering images etc

GTHUMB ....

  This is probably the best gnome tool for viewing and
  organising images.

  * view jpgs and gifs with thumbnails
  >> find ~ -name '*.jpg' -o -name '*.gif' | xargs gthumb

  == keys
  .. [space] - next image
  .. [backspace] - previous
  ..

QIV ....

  appears in active development.

  @@ http://qiv.spiegl.de/
    the official home of qiv

  * open all images specified in the text file 'images.txt' (one per line)
  >> qiv -F images.txt
  >> qiv --file images.txt

  * open qiv with a window of width 200 (pixels?)
  >> qiv -x 200

  * display all jpeg images in the users home folder and subfolders
  >> find ~ -name '*.jpg' | xargs qiv

  * display all jpg and gif images shrinking to fit them in the window
  >> find ~ -name '*.jpg' -o -name '*.gif' | xargs qiv -t

  == qiv keystroke commands
  .. [space] - next image
  .. [backspace] - previous image
  .. ? - view keystrokes
  .. q - exit qiv
  ..

ZGV ....

  * view images from a console
  >> zgv

  * the imagemagick image viewer
  >> display

  * view all images in this and subfolders which have 'tree' in the filename
  >> display $(find . -name '*tree*')

  * view the image 'tree.jpg' as ascii-art (a text representation of the photo)
  >> asciiview tree.jpg   ##(then press 's' to save the ascii photo)

  * a quick image viewer for X windows
  >> qiv

  * another image viewer 
  >> showimg

IMAGE MAGICK DISPLAY ....
  
  * browse through all "gif" images in the current folder "gallery" style
  >> display 'vid:*.gif'

  * browse all "gif" images in the imagemagick/examples folder
  >> display 'vid:/usr/doc/imagemagick/examples/*.gif

 == imagemagick "display" viewer commands
 ..
 .. [SPC],  Display the next image specified on the command line.
 .. [BKSP], Display the previous image specified on the command line.
 .. C-q,  Quit displaying the image and exit display.
 .. C-s,  Write the image to a file.
 .. <, Halve the image size.
 .. >,      Double the image size.
 .. -,      Return the image to its original size.
 .. /,      Rotate image 90 degrees clockwise.
 .. \,      Rotate image 90 degrees counter-clockwise.
 .. ?,      Open a new window with information about the image
 .. h,      Toggle a horizontal mirror image.
 .. v,      Toggle a vertical mirror image.
 ..

  * create an html and thumbnail image gallery
  >> galrey

  * debian: imseek, imview, paul

  * Flatten a RGBA image onto a white background.
  >> composite -compose Over rgba.png -tile xc:white -geometry `identify rgba.png | sed 's/[^ ]* [^ ]* \([^ ]*\) .*/\1/g'` rgb-white.png

  * Find jpeg images and copy them to a central location
  >> find . -iname "*.jpg" -print0 | tr '[A-Z]' '[a-z]' | xargs -0 cp --backup=numbered -dp -u --target-directory {location} &

  * Upload images to omploader.org from the command line.
  >> ompload() { curl -F file1=@"$1" http://omploader.org/upload | awk '/Info:|File:|Thumbnail:|BBCode:/{gsub(/<[^<]*?\/?>/,"");$1=$1;print}'; }

IMAGE METADATA ....

  * Remove EXIF data from images with progress
  >> i=0; f=$(find . -type f -iregex ".*jpg");c=$(echo $f|sed "s/ /\n/g"| wc -l);for x in $f;do i=$(($i + 1));echo "$x $i of $c"; mogrify -strip $x;done

OBTAINING IMAGES ....

  * Grab all images with the tags 'bitch' and 'bw' from a flickr
  >> for URL in `wget -O - http://api.flickr.com/services/feeds/photos_public.gne?tags=bitch,bw 2>/dev/null | grep -E -o "http[^ ]+?jpg" | grep -v "_m" | uniq | grep -v 'buddy' `; do FILE=`echo $URL | grep -E -o "[0-9a-z_]+\.jpg"`; curl $URL > $FILE; done;

SCREENSHOTS ....

  == tools for screen capture
  .. import - makes screen shots, part of 'imagemagick' package.
  .. scrot - a simple command line screen capture utility 
  .. screencapture - the macosx (jaguar) utility
  ..

  The process of creating an image from what is currently displayed
  on the computer screen is generally known as "screen capture" or a
  "screenshot"

  * take a screenshot of the desktop window after 5 seconds, and display it
  >> import -pause 5 -window root desk.png; display desk.png
  >> scrot -d 5 desk.png; display desk.png    ##(the same)

  Using a pause like this before taking the screenshot, allows you
  to rearrange the windows on the desktop if you so desire.

  * take a screen shot of the whole screen and save it to 'test.png' 
  >> scrot test.png

  * take a low-quality screen shot in 'test.png' and display it
  >> scrot -q 10 test.png; feh test.png

  * on macosx capture the whole screen as a jpg image and display it
  >> screencapture -tjpg test.jpg; open test.jpg

  * take a screen shot of the 4th virtual console saved in 'screenshot'
  >> cat /dev/vcs4 > screenshot  ##(this is an old way of doing it)

SCREENSHOTS OF WINDOWS ....

  Sometimes you may only want a screenshot (image file) of 
  a particular window on the computer screen, rather than the whole 
  monitor.

  * make an image of the currently focussed window and save as 'test.jpg'
  >> scrot -u test.jpg

  * capture a window, with its window frame, save in the file 'i.png'
  >> import -frame i.png 
  
  After typing this, left-click on the window you want to capture.
  In other words the technique above, is an 'interactive' technique
  for capturing an image of a screen 

ADVANCED SCREENSHOTS ....

  * easily create and share x screen shots (local webserver version)
  >> scrot -e 'mv $f \$HOME/public_html/shots/; echo "http://\$HOSTNAME/~\$USER/shots/$f" | xsel -i; feh `xsel -o`'

  * easily create and share x screen shots (remote webserver version)
  >> scrot -e 'mv $f \$HOME/shots/; sitecopy -u shots; echo "\$BASE/$f" | xsel -i; feh `xsel -o`'

  * create an screenshot, upload it to your server via scp ...
  >> FILE="`date +%m%d%H%M%S`.png"; URL="http://host/path/$FILE"; TMP="/tmp/$FILE"; import -frame $TMP; scp $TMP user@host:/path/; rm $TMP; firefox "$URL"


META DATA ....

EXIF DATA ....

  * command to change the exif date time of a image
  >> exiftool -DateTimeOriginal='2009:01:01 02:03:04' file.jpg

  * set timestamp in exif of a image
  >> exiv2 -M"set Exif.Photo.DateTimeOriginal `date "+%Y:%m:%d %H:%M:%S"`" filename.jpg

  * change exif data in all jpeg's
  >> for f in *.jpg; do exif --ifd=0 --tag=0x0110 --set-value="LOMO LC-A" --output=$f $f; exif --ifd=0 --tag=0x010f --set-value="LOMO" --output=$f $f; done }

  * move all images in a directory into a directory hierarchy
  >> exiftool '-Directory<DateTimeOriginal' -d %Y/%m/%d dir

IMAGE INFORMATION ....

 @@ http://www.imagemagick.org/script/escape.php
    lists all possible image information codes

 # use the image magick "identify" command with the -format switch

  * show all image formats supported by image magick
  >> identify -list format

  * show the width x height of the image "bird.png"
  >> identify -format "%wx%h" bird.png  ##(prints "16x20" for example)

  * rename all "png" files, so that the name includes the width and height
  >> for f in *.png; do rename "s/\./-"$(identify -format "%wx%h" $f)"./" $f; done

  * Identify name and resolution of all jpgs in current directory
  >> identify -verbose *.jpg|grep "\(Image:\|Resolution\)"

 o- 
  - For example "tree.png" --> "tree-16x30.png"
  - this assumes the file name has only 1 "." character)
  - use the "rename -n" switch to just see what would be renamed, but do nothing)
  - this is rather slow on my bash shell
  -

  * another way to do the same thing
 ------------------------------------------------------------------------
  for f in *.png 
    do mv $f ${f/.*/}-$(identify -format "%wx%h" $f)${f/*./.}; done 
 ,,,

OPTIMIZING IMAGES ....

  * optimize png images
  >> debian: optipng

IMAGE MAGICK BUILT IN PATTERNS ....

  @@ http://www.imagemagick.org/script/formats.php
     a list of all built in patterns which can be referenced as 
     if they were an image

  pattern:checkerboard

IMAGE FORMATS ....

 == image format notes
 ..
 .. png, is a lossless format, has transparency
 .. jpg, highly compressable, lossy, no transparency
 .. gif, animations possible, compressed,
 ..

TRANSFORMING IMAGES ....

 ## generally "mogrify" modifies the image itself whereas "convert"
 ## creates a copy of the changed image. The exception is where the 
 ## -format option is used with "mogrify"

 @@ http://www.imagemagick.org/Usage/ 
   lots of usage examples
 @@ http://dsl.org/cookbook/cookbook_23.html#SEC338

  * scale and transform images
  >> mogrify ##(changes the image)
  >> convert ##(doesnt change)

  * reduce in size all jpeg images in the folder by 50% 
  >> mogrify -resize 50% *.jpg    ##(the images are changed)

  * reduce by 50% an image and save the reduced image as "rose2.jpg"
  >> convert rose.jpg -resize 50% rose2.jpg

  * rotate an image by 90 degrees where the height exceeds the width
  >> mogrify -rotate '90<' image.jpeg

  * rotate an image where the width exceeds the height
  >> mogrify -rotate '90>' image.jpeg

  * reduce the colors of an image to 4 with color diffusion
  >> mogrify -colors 4 -dither image.jpeg
 
  * convert an image to black and white
  >> mogrify -monochrome colourful.jpeg

  * change the brightness of the image "cat.jpg"
  >> mogrify -gamma .8 cat.jpg

  * add a grey border 2px wide and 4px high around an image
  >> mogrify -border 2x4 cat.jpg
  >> mogrify -frame 8x8 cat.jpg    ##(a bevelled border)

CONVERTING IMAGE FORMATS ....

  * convert the jpeg image "rose.jpg" to the "png" format.
  >> convert rose.jpg rose.png

  * convert all png images in the current folder to the jpeg format
  >> mogrify -format jpg *.png    ##(a copy of the images is created)

  * convert a large number of "gif" images to the "png" format
  >> find . -name "*.ico" | xargs mogrify -format png 
  ##(this is very fast)

  * batch convert nikon raw (nef) images to the 'jpeg' format
  >> ufraw-batch --out-type=jpeg --out-path=./jpg ./*.NEF

  * Convert all WMF images to SVG recursively ignoring file extension
  >> find . -type f -iname '*.wmf' | while read FILE; do FILENAME="${FILE%.*}"; wmf2svg -o ${FILENAME}.svg $FILE; done

  * Convert your favorite image in xpm for using in grub
  >> convert image123.png -colors 14 -resize 640x480 grubimg.xpm

  * recursively find 'tiff' images, convert to jpegs and delete
  >> find . -name '*'.tiff -exec bash -c "mogrify -format jpg -quality 85 -resize 75% {} && rm {}" \;

  * Batch resize all images in the current directory 
  >> mogrify -resize 800\> *

BLACK AND WHITE ....

  * Create black and white image
  >> convert -colorspace gray face.jpg gray_face.jpg

PHOTOS SOFTWARE

  @@ gtkam
     photo editing software
  @@ gphoto2
     command-line interface for manipulating images
  @@ printoxx
     image printing, editing

ANIMATION ....

 # frame numbers start at 0

  * show information for all the frames in an animation
  >> identify tree.ico

  * display how many frames an animation has
  >> identify tree.gif | wc -l

  * extract the 2nd frame from an animated gif and save to "new.gif"
  >> convert animation.gif[frame1] new.gif

  * delete all frames except the first 3  (0, 1, 2)
  >> convert animation.gif -delete 3--1 frames012.gif
 ##(-1 refers to the last frame in an animation)

  * split an animation into its constituent frames
  >> convert canvas_prev.gif -scene 1 +adjoin  frame_%03d.gif

  * convert a set of frames to an animation
  >> convert frame_???.gif  anim_rebuilt.gif
 ##(combines frame_001.gif frame_002.gif etc)

  * show only image files which have only one frame (are not animations)
  >> for i in $(find . -name "*" | head -200); do echo -n $i "#"; identify $i | wc -l  ; done | grep "#1$"
 ##(this is rather horrifyingly slow, about 10 file per second)

ANIMATED GIFS ....
 
  * gifsicle

ICONS ....

  * Create a favicon
  >> convert -colors 256 -resize 16x16 face.jpg face.ppm && ppmtowinicon -output favicon.ico face.ppm

RESIZING IMAGES ....

  * Resize photos without changing exif
  >> mogrify -format jpg -quality 80 -resize 800 *.jpg

  * resize(1/2) the image using imagemagick
  >> convert -resize 50%x50% image{,_resize}.jpg

CROPPING WHITESPACE FROM IMAGES ....
  
  * crop out all whitespace around an image and convert to 'jpg'
  >> convert -crop WxH+0+0 file.ps file.jpg  ##(width and height)
  >> convert -trim +repage file.ps file.jpg  ##(untested)

  * crop all whitespace from a postscript document and convert to png
  >> pstoimg -type png -crop a -trans old.ps

  * crop all whitespace from a pdf file and convert to png
  >> pdftops old.pdf; pstoimg -type png -crop a -trans old.ps
  
  But if the pdf has page numbers, this wont work as you
  were hoping. 

CROPPING IMAGES ....

  * crop a 32x32 pixel block starting at pixel (16,16) and save to "new.gif"
  >> convert tree.gif -crop 32x32+16+16 new.gif

  * divide an image into 20x20 pixel blocks and save to zz-nn.png etc
  >> convert tree.gif -crop 20x20 zz.png  ##(creates files zz-1.png, zz-2.png etc)

  * crop a 32x32 pixel block from the center of the image and save in "new.png"
  >> convert tree.png -gravity Center -crop 32x32+0+0 new.png

  * crop a 20x20 block, 5 pixels from the bottom and centered horizontally
  >> convert tree.png -gravity South -crop 20x20+0+5 new.gif

  * crop the top left hand quarter of the image 
  >> convert tree.png -crop 50%x+0+0 new.png
 ##(the height of the new image is 1/2 the height of the old image)

  * crop a 20 pixel vertical strip starting at the top left hand corner
  >> convert tree.png -crop 20x0+0+0 new.png 

  * crop a 30 pixel horizontal strip starting at the top left hand corner
  >> convert tree.png -crop 0x30+0+0 new.png 

  * convert "tree.png" into a series of 20 pixel wide vertical strips 
  >> convert tree.png -crop 20x strip-%d.png

  * remove a 10 pixel horizontal strip from the top of "tree.png"
  >> convert tree.png -crop +0+10 new.png

  * remove a 10 pixel horizontal strip from the bottom of "tree.png"
  >> convert tree.png -gravity South -crop +0+10 new.png
  >> convert tree.png -crop -0-10 new.png   ##(the same)

  * remove a 10 pixel horizontal strip from the bottom of all png files
  >> mogrify -gravity South -crop +0+10 *.png
 ##(the actual image files are modified, no copies are made) 

  * remove 20 pixels from the top and bottom of the image "tree.png"
  >> convert tree.png -shave 0x20 new.png 

ADDING EFFECTS TO IMAGES ....

  * Add a shadow to a picture 'old.png'
  >> convert old.png \( +clone -background black -shadow 60x5+10+10 \) +swap -background none -layers merge +repage new.png

SPLICING ....

  * splice a 10 pixel white horizontal band in the image, at vertical pixel 30
  >> convert tree.png -background white -splice 0x10+0+30 new.png

  * add a 10 pixel row of blue space at the bottom of the image.
  >> convert tree.png -gravity south -background blue -splice 0x10 new.png 

CREATING IMAGE MONTAGES ....
 
 # An image montage is combining several images side by side, resizing
 # the images and arranging in blocks with spacing.
 # In an image montage all the images are the same size.

  * create a horizontal strip of images "tree-1.gif" etc resizing to 16x16 pixels 
  >> montage tree-[1-7].gif -tile 9x1  -geometry 16x16+1+1  new.gif
 ##(images are laid out "row-wise")

  * create a 3x3 block of images resized to 16 pixels with 1 pixel spacing
  >> montage tree-[1-7].gif -tile 3x3 -geometry 16x16+1+1 new.gif
 ##(if there are not enough images to fill the block, white space is created)

  * create a two row montage with an unknown number of images
  >> montage tree-*.gif -tile x2 -geometry 16x16+1+1 new.gif
 ##(the necessary columns are calculated by imagemagick)

  * create a 1 row montages, 5 pixel spaces, blue background and image shadow
  >> montage balloon.gif medical.gif -tile x1 -shadow \ 
  >>   -geometry +5+5 -background lightblue new.jpg

  * create a 1 row montage putting a 3 pixel frame around each image
  >> montage balloon.gif medical.gif -tile x1 -frame 3 -geometry +5+5 new.jpg 

  * create a 1 row montage with image-magic "built in" images
  >> montage logo: rose: -tile x1 -frame 3 -geometry +5+5 new.jpg 

  * create a 1 row montage with a title above the montage
  >> montage balloon.gif medical.gif -tile x1  -geometry '60x60+2+2>' \ 
  >>   -title 'My Images' titled.jpg

  * create a 1 row montage with a gap in the middle
  >> montage medical.gif null: present.gif -tile x1 -geometry +2+2 new.jpg

  * create a montage with the file name under the image, silver background
  >> montage -label '%f' x.png -font Arial -pointsize 30 -geometry +0+0 -background silver xy.png

  * create an overlapped and rotated image montage
  >> montage null: font_*.gif null: -background none -rotate 30 \
  >>   -background white -tile x1 -geometry -8+2  montage_rot_overlap.jp

HTML THUMBNAIL GALLERIES ....

 @@ http://www.imagemagick.org/Usage/thumbnails/

  * create an html thumbnail gallery with image map
  >> montage -label '%t\n%[width]x%[height]' \
  >>    -size 512x512 '../img_photos/*_orig.*[120x90]' -auto-orient \
  >>    -geometry +5+5 -tile 5x  -frame 5  -shadow  photo_index.html

HTML IMAGE MAPS ....

  * create an image map with a 4 pixel gap between images, with 10 columns
  >> montage '*.png' -geometry +4+4 -tile 10x map.html
  ##(this produces 3 files, an html file, shtml file, and a png file)
  ##(note that "montage" expands the file list, not the shell)

  * create an html image map in "png" format and convert to "jpg" to reduce size
  ------------------------------------------------------------------------------

   montage '../img_photos/*_orig.*[120x90]' -auto-orient \
      -geometry +5+5 -tile 5x  -frame 5  -shadow  photo_jpeg.html
   convert photo_jpeg.png photo_jpeg.jpg
   perl -i -lpe 's/src="photo_jpeg.png"/src="photo_jpeg.jpg"/' photo_jpeg.html
   rm -f photo_jpeg.png photo_jpeg_map.shtml

   ,,,

CREATING A MONTAGE OF LOTS OF IMAGES ....

  * create a montage of the first 300 files in the current folder
  >> montage $(ls | head -300) -tile 45x -geometry +3+3  new.png

  * create montage of 300 icons each of the files in the current folder
 ---------------------------------------------------------------------
    for j in $(seq 300 300 36000); 
    do
      montage $(ls | head -$j | tail -300) -tile 40x -geometry +3+3 fav-$i.html;
    done
 ,,,

  * quote the file list to avoid shell file argument limits
  >> montage '*.png' -tile 45x -geometry +3+3  new.png
 ##(the "montage" tool expands the file list instead of the shell)

UNICODE CHARACTERS IN IMAGES ....


  * put unicode characters into an image
  --------------------------------------
  ## ???? not working 

  printf "\u201Cdouble\u2 01D" | \
        convert -background lightblue -fill blue -pointsize 36 \
                      label:@-  label_quotes.gif
  ,,,

RENAMING IMAGES ....

  * rename images according to exif or jpeg metadata
  >> exiv2 rename *.jpg

  * extract digital camera info from exif jpeg files.
  >> jhead -n%Y%m%d-%H%M%S *.jpg

  * a gtk based image renamer
  >> gwenrename

IMAGE CAPTIONS ....

  * add a caption at the bottom of an image in 15px of white space 
  >> convert tree.png -gravity south -background LimeGreen -splice 0x15 \
  >>    -annotate 0x0 'Tree' new.png 

  * draw a label at the bottom of the image in a grey rectangle (superimposed)
  >> convert tree.png -fill '#0008' -draw 'rectangle 5,128,114,145' \
  >>   -fill white -annotate +10+141 'Tree' new.png 

  * the same
  >> convert tree.png -fill white -undercolor '#00000080' -gravity South \
  >> -annotate +0+5 ' Faerie Dragon ' tree.jpg

  * label an image with its file name and size in pixels on a blue background
  >> montage balloon.gif -tile x1 -geometry '90x32>' -pointsize 10 \
  >>    -set label '%f\n%wx%h' -background SkyBlue new.jpg

COMBINING IMAGES ....

  * overlay "tree.gif" in the center of "mountain.gif" and save to "new.gif"
  >> composite -gravity center tree.gif mountain.gif new.gif

  * position "point.gif" exactly within "tree.gif" and save as "new.gif"
  >> composite -geometry +31+105  point.gif tree.gif new.jpg
  
IMAGE BORDERS ....

  * add 10 pixel red side bars to an image
  >> convert tree.png -bordercolor Red -border 10x0 new.png 

IMAGES OF TEXT ....
 
  * show what fonts are available with image magick (for writing images)
  >> convert -list type       ##(for IM older than v6.3.5-7)
  >> convert -list font       ##(for newer versions)

  * divide an image of text into text lines
  >> divide_vert

  * create an image of "Tree" blue on white background
  >> convert -background white -fill blue -font Candice \
  >>   -pointsize 72 label:Tree label.gif
  ##(check that the font is available with the command above)

  * create an image, size 165x70, of text "Tree" with text centered in image
  >> convert -fill blue -font Helvetica -size 165x70  -pointsize 24 \
  >> -gravity center label:Tree tree.gif

  * create an image of text, with text font size auto-fitted to image size
  >> convert -fill blue -font Candice -size 165x70 label:Tree new.gif

  * create image of text with the width of the image autofitted to the text width
  >> convert -fill blue -font Candice -size 160x label:Tree new.gif
  ##(in this way the text fills the image box well)

  * for multiline labels IM version 6.2.5 or later is required

  * create a label with text from the file "/etc/motd"
  >> convert -background lightblue -fill blue label:@/etc/motd new.gif

  * create an image label from text from standard input
  >> echo "hello!" | convert -fill blue label:@- new.gif

  * create an image label in which the text wraps on long lines
  >> convert -fill blue -font Courier -pointsize 36 -size 320x \
  >>  caption:'This is long caption line.' new.gif

  * create an image label in which the text wraps on long lines and is centered
  >> convert -fill blue -font Courier -pointsize 36 -size 320x \
  >>  -gravity center caption:'This is long caption line.' new.gif
  ##( >= IM version 6.2.0)

  * image label with text size autofitted to the image size
  >> convert -background lightblue -fill blue -font Candice -size 320x140 \
  >>    caption:'This text is resized to best fill the space given.' \
  >>                     caption_filled.gif
  ##( >= IM v6.3.2)

  * create an image of the word "shadow" with a shadow, magenta and red
  * with a transparent background.
  ---------------------------------------------------------------------

  convert -size 320x85 xc:transparent -font Bookman-DemiItalic -pointsize 72 \
    -draw "text 25,60 'shadow'" -channel RGBA -gaussian 0x6 -fill darkred \
    -stroke magenta -draw "text 20,55 'shadow'" fuzzy-magick.png
  ,,,

  * create white text with a hard shadow on a transparent background
  ------------------------------------------------------------------

  convert -size 320x100 xc:transparent -font Bookman -pointsize 72 \
    -fill black -draw "text 28,68 'Tree'" \
    -fill white -draw "text 25,65 'Tree'" new.jpg

  ##(the trick is to draw the text twice with a slight displacement)
  ,,,

  * create a "bevelled" font using the "shade operator, white with black edges
  ----------------------------------------------------------------------------
    convert -size 320x100 xc:black -font Bookman -pointsize 72 \
            -fill white -annotate +25+65 'Tree' -shade 140x60 new.jpg
  ,,,

DRAWING COMMANDS TO CREATE IMAGES ....

  * draw a white rectangle with a black border in a 100x60 image
  >> convert -size 100x60 xc:skyblue -fill white -stroke black \
  >>      -draw "rectangle 20,10 80,50" new.gif

COMPRESSING IMAGES ....

  * reduce the quality (and file size) of an image, and save in "tree-80.jpg"
  >> convert tree.jpg -quality 80% tree-80.jpg

  * reduce a jpeg even more
  >>  -sampling-factor 2x1

IMAGE FORMATS ....

  * convert a jpg image to the "png" format
  >> convert tree.jpeg tree.png     ##(a copy in the new format is made)

IMAGE EDITORS ....
 
  @@ deb: grokking-the-gimp
     a book about using gimp

  * xmorph, gimp

  * a simple paint program
  >> xpaint 

  * edit bitmaps, pixmaps
  >> tkpaint, bitmap

THREE D IMAGE EDITORS ....

  * sced, moonlight

VISUAL ART

IMAGE REPOSITORIES

  The open clip art library.
  
  @@ http://openclipart.org/media/tags
    a tag cloud of open clip art

  == packages
  .. openclipart
  .. openclipart-png
  .. create-resources - brushes, gradients etc
  ..

ASCII IMAGES ....

  * a demonstration of the aview tool
  >> bb

  == ascii art tools
  .. aview - 
  .. cadubi - an ascii art editor
  .. aewan - an ascii art editor
  .. textdraw - create ascii geometric figures
  .. figlet - create ascii text banners
  .. cowsay - create ascii pictures of cows with speach bubble
  .. banner - show a large ascii banner text
  ..

  * display a text banner with a 50 character width
  >> banner -w50 'Hello'

  * draw a box with an ascii-art dog design around the text 'hello'
  >> echo hello | boxes -d dog
  
  * view a video using only 'ascii art' 
  >> mplayer -vo aa <video file>

  * bulk dl files based on a pattern
  >> curl -O http://hosted.met-art.com/generated_gallery/full/061606AnnaUkrainePasha /met-art-free-sample-00[00-19].jpg

PATTERNS AND TILINGS ....

  * kali
TEXT AND CHARACTER RECOGNITION
 
 The process of extracting text data from an image file (which has
 usually been obtained by scanning a page of typed text) is known as
 "ocr" for Optical Character Recognition

 == ocr tools
 .. tesseract-ocr - Command line OCR tool, said to be mature
 .. ocropus - google sponsored ocr tool, uses tesseract
 .. gocr - 
 .. ocrad - 
 .. clara - 
 .. unpaper - improve the quality of scanned text images
 ..

SVG SCALABLE VECTOR GRAPHICS

  An svg image is really just a plain text file in xml format
  This is really good, because it means you can create images using 
  a text editor.

  * an empty svg image with a width and a height
  ----------------------------------------------
  <?xml version="1.0" standalone="no"?>
  <!DOCTYPE svg PUBLIC 
     "-//W3C//DTD SVG 20000802//EN" 
     "http://www.w3.org/TR/2000/CR-SVG-20000802/DTD/svg-20000802.dtd">
  <svg width="225" height="250">
  </svg>
  ,,,

  * create a rectagle in an svg file
  >> <rect  x="10" y="40" width="150" height="500"/>

  * create 3 rectangle with similar graphical properties 
  ------------------------------------------------------
  <?xml version="1.0" standalone="no"?>
  <!DOCTYPE svg PUBLIC 
     "-//W3C//DTD SVG 20000802//EN" 
     "http://www.w3.org/TR/2000/CR-SVG-20000802/DTD/svg-20000802.dtd">
  <svg width="225" height="250">
  <g style="fill:white; stroke:blue; stroke-width:4;">
    <rect  x="10" y="40" width="150" height="500"/>
    <rect  x="160" y="40" width="50" height="500"/>
    <rect  x="10" y="10" width="150" height="30"/>
  </g>
  </svg>
  ,,,

  * a filled rectangle
  --------------------
  <?xml version="1.0" standalone="no"?>
  <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" 
    "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">

  <svg width="100%" height="100%" version="1.1"
       xmlns="http://www.w3.org/2000/svg">
  <rect width="300" height="100" 
        style="fill:rgb(0,0,255);stroke-width:1;stroke:rgb(0,0,0)"/>
  </svg>
  ,,,

  * a rectangle with border and fill opacity
  ------------------------------------------
  <?xml version="1.0" standalone="no"?>
    <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" 
    "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
    <svg width="100%" height="100%" version="1.1"
    xmlns="http://www.w3.org/2000/svg">
    <rect x="20" y="20" width="250" height="250"
    style="fill:blue;stroke:pink;stroke-width:5;
    fill-opacity:0.1;stroke-opacity:0.9"/>
  </svg>
  ,,,

  * a rectangle with rounded corners
  ----------------------------------
    <rect x="20" y="20" rx="20" ry="20" width="250" height="100"
    style="fill:red;stroke:black;stroke-width:5;opacity:0.5"/>
  ,,,

ELLIPSES ....

  * an ellipse
  ------------
  <ellipse cx="300" cy="150" rx="200" ry="80"
  style="fill:rgb(200,100,50);stroke:rgb(0,0,100);stroke-width:2"/>
  ,,,

  <ellipse cx="240" cy="100" rx="220" ry="30"
  style="fill:yellow"/>

  <ellipse cx="220" cy="100" rx="190" ry="20"
  style="fill:white"/>

  * 2 elllipses one inside the other
  ----------------------------------
  <ellipse cx="240" cy="100" rx="220" ry="30"
  style="fill:yellow"/>

  <ellipse cx="220" cy="100" rx="190" ry="20"
  style="fill:white"/>
  ,,,

CIRCLES ....

  * a circle with border
  >> <circle cx="100" cy="50" r="40" stroke="black" stroke-width="2" fill="red"/>

  * Convert a SVG file to grayscale
  >> inkscape -f file.svg --verb=org.inkscape.color.grayscale --verb=FileSave --verb=FileClose

  * Convert all WMF images to SVG recursively ignoring file extension
  >> find . -type f -iname '*.wmf' | while read FILE; do FILENAME="${FILE%.*}"; wmf2svg -o ${FILENAME}.svg $FILE; done

POLYGONS ....

  * a triangle
  ------------
  <polygon points="220,100 300,210 170,250"
  style="fill:#cccccc;stroke:#000000;stroke-width:1"/>
  ,,,

  * a 4 sided polygon
  -------------------
  <?xml version="1.0" standalone="no"?>
  <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" 
  "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">

  <svg width="100%" height="100%" version="1.1"
  xmlns="http://www.w3.org/2000/svg">

  <polygon points="220,100 300,210 170,250 123,234"
  style="fill:#cccccc;stroke:#000000;stroke-width:1"/>

  </svg>
  ,,,


  * a polyline
  ------------
    <polyline points="0,0 0,20 20,20 20,40 40,40 40,60"
    style="fill:white;stroke:red;stroke-width:2"/>
  ,,,

PATHS 

  * a piece of text surrounded by a thick round box
  -------------------------------------------------
  <path fill="none" stroke="#D90000" stroke-width="10" 
       d="M50,90 C0,90 0,30 50,30 L150,30 C200,30 200,90 150,90 z" />
  <text fill="#FFFFFF" stroke="black" font-size="45" font-family="Verdana" x="52" y="76">SVG</text>
  ,,,

GRADIENTS ....

  * an ellipse with a linear colour gradient
  ------------------------------------------
    <?xml version="1.0" standalone="no"?>
    <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" 
    "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">

    <svg width="100%" height="100%" version="1.1"
    xmlns="http://www.w3.org/2000/svg">

    <defs>
    <linearGradient id="orange_red" x1="0%" y1="0%" x2="100%" y2="0%">
    <stop offset="0%" style="stop-color:rgb(255,255,0);stop-opacity:1"/>
    <stop offset="100%" style="stop-color:rgb(255,0,0);stop-opacity:1"/>
    </linearGradient>
    </defs>

    <ellipse cx="200" cy="190" rx="85" ry="55"
    style="fill:url(#orange_red)"/>

    </svg>
    ,,,

   * a circle with a ball like colour gradient
   -------------------------------------------

   <defs>
   <radialGradient id="grey_blue" cx="50%" cy="50%" r="50%" fx="50%" fy="50%">
   <stop offset="0%" style="stop-color:rgb(200,200,200);stop-opacity:0"/>
   <stop offset="100%" style="stop-color:rgb(0,0,255);stop-opacity:1"/>
   </radialGradient>
   </defs>

   <ellipse cx="230" cy="200" rx="110" ry="100"
   style="fill:url(#grey_blue)"/>
   ,,,

ANIMATION ....
 
  * a rectangle which fades over 5 seconds repeatedly
  ----------------------------------------------------
  <rect x="20" y="20" width="250" height="250" style="fill:blue">
  <animate attributeType="CSS" attributeName="opacity" 
  from="1" to="0" dur="5s" repeatCount="indefinite" />
  </rect>
  ,,,
  
  * apply lots of animations to a rectangle
  -----------------------------------------
   <rect id="rec" x="300" y="100" width="300" height="100" style="fill:lime"> 
   <animate attributeName="x" attributeType="XML" begin="0s" dur="6s" fill="freeze" from="300" to="0"/> 
   <animate attributeName="y" attributeType="XML" begin="0s" dur="6s" fill="freeze" from="100" to="0"/> 
   <animate attributeName="width" attributeType="XML" begin="0s" dur="6s" fill="freeze" from="300" to="800"/> 
   <animate attributeName="height" attributeType="XML" begin="0s" dur="6s" fill="freeze" from="100" to="300"/> 
   <animateColor attributeName="fill" attributeType="CSS" from="lime" to="red" begin="2s" dur="4s" fill="freeze"/>
   </rect>
  ,,,,

  * animate a rectangle along a path
  ----------------------------------
  <g transform="translate(100,100)">
  <text id="TextElement" x="0" y="0" style="font-family:Verdana;font-size:24"> It's SVG!
  <animateMotion path="M 0 0 L 100 100" dur="5s" fill="freeze"/>
  </text>
  </g>
  ,,,

DOCUMENT-NOTES:
 
  # this section contains information about the document and
  # will not normally be printed.

  # A small (16x16) icon image to identify the book
  document-icon:

  # A larger image to identify or illustrate the title page
  document-image:

  # what sort of document is this
  document-type: book

  # in what kind of state (good or bad) is this document 
  document-quality: just starting

  document-history:
  @@ 11 may 2010
     I imported a number of recipes from the 'linux-book.txt' mainly
     about using image-magic. The file has about 900 lines currently.
     The image section in the linux-book.txt was growing too large and
     thus I decided to start this book.
  @@ 12 may 2010
     Adding some information about editing svg as text

  # who wrote this
  authors: mjbishop at fastmail dot fm

  # a short description of the contents, possible used for doc lists
  short-description: viewing and manipulating images using linux tools

  # A computer language which is contained in the document, if any
  code-language: bash

  # the script which will be used to produce html (a webpage)
  make-html: ./booktohtml.cgi

  # the script which will produce 'LaTeX' output (for printing, pdf etc)
  make-latex: ./booktolatex.cgi

  * Preview of a picture in a terminal
  >> img test.jpg
 
  * Convert PDF to JPG
  >> for file in `ls *.pdf`; do convert -verbose -colorspace RGB -resize 800 -interlace none -density 300 -quality 80 $file `echo $file | sed 's/\.pdf$/\.jpg/'`; done
 
  * for all flv files in a dir, grab the first frame and make a jpg.
  >> for f in *.flv; do ffmpeg -y -i "$f" -f image2 -ss 10 -vframes 1 -an "${f%.flv}.jpg"; done
 
  * Adding formatting to an xml document for easier reading
  >> xmllint --format <filename> > <output file>