The Linux Image Book

Table of Contents

last revision
05 May 2015, 11:56am
book quality
just starting


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 all images with a '.jpg' extension in the '/usr/share' tree

 find /usr/share/backgrounds -iname '*.jpg' | less

find 'png' images in the 'icons' folder suppressing error messages

 find /usr/share/icons -iname '*.png' 2>/dev/null | less

display a dialog to choose one out of all '.jpg' user files.

 xdg-open "$(locate -i '/home/*.jpg' | zenity --list --column=)"

display a list of jpg files and allow user to choose one to open

 IFS=$'\n'; select f in $(locate -i '/home/*.jpg'); { xdg-open $f; break; }

use 'locate' to find png images in the icons folder

 sudo updatedb; locate */icons/*.png | less

"Locate" is faster than "find" because it uses a database to search for the files, but the database must be kept up-to-date with "updatedb".

find all real png image files in the 'icons' folder

 find /usr/share/icons/ | xargs file | grep -i 'png image' | less

find all jpeg image files in the users home folder

 find ~ | xargs file | grep -i 'jpeg' | less

find .jpg images which are greater than 1 megabyte in size

 find /usr/share/ -iname '*.jpg' -size +1M 2>/dev/null | less

Find corrupted jpeg image files

 find . -name "*jpg" -exec jpeginfo -c {} \; | grep -E "WARNING|ERROR"

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

 convert images*.* big.pdf

find all image files in the 'icons' folder

 find /usr/share/icons/ | xargs file | grep image | less

find all real image files on the computer

 sudo find / | xargs file | grep ' image' | less

Analysing Images ‹↑›

display information about an image using 'file'

 file /usr/share/backgrounds/Frog.jpg

Width And Height ‹↑›

show the width x height of the image "bird.png"

 identify -format "%wx%h" bird.png  prints "16x20" for example

Determine an image's dimensions

 identify -format "%wx%h" /usr/share/backgrounds/Frog.jpg

show all jpegs wider than 3000 pixels

 for f in *.jpg;{ w=$(identify -format "%w" $f); [ $w -gt 3000 ] && echo $f $w;}

display width by height (eg: 3664x2748)for all jpeg images in this folder

 for f in *.jpg; { identify -format "%wx%h %f" $f; }
 identify -format "%wx%h %f" *.jpg   all one one line

display width and height (w x h) for all user jpg images

 locate -i /home/*.jpg | xargs -I{} identify -format "%wx%h %f" "{}"

locate all images more than 1000 pixels wide

 locate -i /home/*.jpg | xargs -I{} identify -format "%w:%f" "{}"|grep '^....:'

choose a wide image to view

 xdg-open "$(locate -i /home/*.jpg | xargs -I{} identify -format '%w:%d/%f' '{}'|grep '^....:' |zenity --list --column= | sed 's/^.*://')"

show the widest 20 images in user folders and view one

 locate -i /home/*.jpg | xargs -I{} identify -format '%w:%d/%f' '{}'|grep '^....:' | sort -rn |head -20

show the widest 20 images in user folders and view one

 xdg-open "$(locate -i /home/*.jpg | xargs -I{} identify -format '%w:%d/%f' '{}'|grep '^....:' | sort -rn |head -20| zenity --width=800 --list --column= | sed 's/^.*://')"

locate all images with fewer than 10 unique colours.

 locate -i /home/*.jpg | xargs -I{} identify -format "%k:%f" "{}"|grep '^.:'

display the dimensions of all the images in a folder

 for f in /usr/share/backgrounds/*.jpg; { identify -format "%wx%h %f" $f; }

print image information about all png images in the current folder

 feh -l *.png

print image information about all png images in a folder

 locate '/home/*.png' | xargs feh -l | less  very slow

print image information with a custom format

 feh -L ... -l *.png

display information about an image using the exiv2 tool

 exiv2 /usr/share/backgrounds/Frog.jpg

Exif And Metadata ‹↑›

Exif data is textual data which is attached to image files by many digital cameras. This information can include the date the photo was taken, the gps coordinates where it was taken etc.

display the "exif" data for the file '1300.jpg'

 exif 1300.jpg | less

Print the IPTC metadata of the image.

 exiv2 -pi image.jpg

rename img_1234.jpg to img_1234_200511.jpg

 exiv2 -r':basename:_%Y%m' rename img_1234.jpg

Sets the latitude to 4 degrees, 15 minutes and 33 seconds north.

 exiv2 -M"set Exif.GPSInfo.GPSLatitude 4/1 15/1 33/1" -M"set Exif.GPSInfo.GPSLatitudeRef N" image.jpg

The Exif standard stipulates that the GPSLatitude tag consists of three Rational numbers for the degrees, minutes and seconds of the latitude and GPSLatitudeRef contains either 'N' or 'S' for north or south latitude respectively.

Exif Timestamps ‹↑›

rename car.jpg to something like 20081217_182505.jpg (the exif timestamp)

 exiv2 rename car.jpg
 exiv2 mv car.jpg   the same

rename "car.jpg" to something like '23-40pm.3mar2001.jpg'

 exiv2 rename -r "%I-%M%p.%d%b%Y" car.jpg

The filename will be taken from the available exif timestamp

add 2 to the month value in the exif timestamp

 exiv2 adjust -O 2 car.jpg

subtract 1 from the hour of the exiv timestamp

 exiv2 ad -a -1 *.JPG

command to change the exif date time of a image

 exiftool -DateTimeOriginal='2009:01:01 02:03:04' file.jpg

Display EXIF tag 0x9003 (DateTimeOriginal)

 exif -t 0x9003 picture.jpg

Comments ‹↑›

print the comment, if any, associated with the image "car.jpg"

 exiv2 -p c car.jpg

sets the exif comment to the ascii string 'a picnic'.

 exiv2 -M"set Exif.Photo.UserComment charset=Ascii a picnic" image.jpg

add a comment to the image file 'snap.jpg'

 exiv2 modify -c"A sunny day" snap.jpg
 exiv2 mo -c"A sunny day" snap.jpg      the same

print the comments from all images which have them

 locate '*.jpg' | xargs -I{} exiv2 -p c "{}" 2>/dev/null | grep -v '^$'

print filenames and comments for those image which have them

 for f in $(locate '*.jpg'); { echo -n "$(basename $f):"; exiv2 -pc $f 2>/dev/null; } | grep -v ':$'

delete the jpeg comment from the exif metadata

 exiv2 -dc car.jpg

delete all exif metadata

 exiv2 -da car.jpg

add exif data to various files -------- add Exif.Image.Artist Ascii "My name" add Exif.Image.Copyright Ascii "Copyright © 2010 My name" ,,,

add data to various files

 exiv2 -m /somewhere/exif-copyright-2010.txt

Camera Model ‹↑›

Exif Thumbnails ‹↑›

extract thumbnail from "picture.jpg" saving to picture.jpg.modified.jpg

 exif -e picture.jpg

Set EXIF tag 0x9003 (DateTimeOriginal) to the given value, writing the new file to picture.jpg.mod

 exif --ifd=EXIF --tag 0x9003 --set-value='2007:09:17 09:30:55' picture.jpg

set the timestamp in the 'exif' data for a image

 exiv2 -M"set Exif.Photo.DateTimeOriginal `date "+%Y:%m:%d %H:%M:%S"`" filename.jpg

change exif data in all jpeg images

 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 timestamp directory hierarchy

 exiftool '-Directory<DateTimeOriginal' -d %Y/%m/%d dir

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

Rotate a set of photos matching their EXIF data.

 jhead -autorot *.jpg

Other Image Information ‹↑›

lists all possible image information codes
exif tools
exiftool - no ubuntu package ?
exiv2 - EXIF/IPTC metadata manipulation tool
exif - small command-line utility to show EXIF information in JPEG files
exifprobe - Read metadata from digital pictures
exiftags - Utility to read Exif tags from a digital camera JPEG file
jhead - manipulate the non-image part of Exif compliant JPEG files
metacam - extract EXIF information from digital camera files

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

show all image formats supported by image magick

 identify -list format

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 ,,,

Managing Images ‹↑›

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

rename, copy and resize to 1100 pixels a set of images interactively

 feh -g640x480 -rA 'g=~/home/mjbishop/Pictures/$(zenity --entry --text "Rename image"); cp %f $g; mogrify -monitor -resize 1100 $g' /home/mjbishop/sf/*

rename, move and resize a set of images interactively

 feh -g640x480 -A 'g=~/new/path/$(zenity --entry --text "Rename image"); mv %f $g; mogrify -monitor -resize 1100 $g' /media/usb/device/*

image magick escape codes
%b - file size
%c - comment properity
%d - directory path
%e - filename suffix
%f - filename (excluding suffix)
%g - page geometry ( = %Wx%H%X%Y )
%h - current image height in pixels
%i - input filename (full path)
%k - number of unique colors
%l - label properity
%m - magick format used during read
%n - number of images in sequence
%o - output filename
%p - index of image in sequence
%q - quantum depth (compile-time constant)
%r - image class and colorspace
%s - scene number (from input)
%t - top of filename
%u - unique temporary filename
%w - current width in pixels
%x - x resolution
%y - y resolution
%z - image depth (as read in)
%A - image alpha channel (true/false)
%C - image compression type
%D - image dispose method
%G - image size ( = %wx%h )
%H - page (canvas) height
%O - page (canvas) offset ( = %X%Y )
%P - page (canvas) size ( = %Wx%H )
%Q - image compression quality
%S - ?? scenes ??
%T - image time delay
%W - page (canvas) width
%X - page (canvas) x offset (including sign)
%Y - page (canvas) y offset (including sign)
%@ - bounding box
%# - signature
%% - a percent sign
\n - newline
\r - carriage return

Viewing Images ‹↑›

a list of all image viewers
As can be seen by the lists below a large number of image viewers and organisers exist for linux. In the first table are listed the ones I consider most useful.

batch photo tools
phatch - make rounded corners among other things
convert - image magick.

show jpegs with thumbnails

 find ~ -name '*.jpg' | xargs mirage

Feh ‹↑›

Feh is fast and flexible for managing images. I concentrate on feh because it integrates with other command line tools.

linux image viewers
f-spot - considered one of the best image viewers
gthumb - a gnome viewer and simple editor
feh - a fast command line driven image viewer
eye of gnome - the official gnome image viewer
xv - an old x windows viewer
xli - another one
aview - ascii image viewer
asciiview -
geeqie - gtk image viewer
gpicview - small image viewer
gqview - simple gtk image viewer emacs style keys
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

nice feh settings for viewing images

 feh --draw-tinted -e "yudit/14" --info "exiv2 %f|grep -i 'size\|name\|time\|comm' " -F $imagedir

Viewing With Feh ‹↑›

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

show the images in /opt/images in full-screen and zoomed to fit

 feh -FZr /opt/images

show all the images in the /opt/images tree

 feh -FZr /opt/images

show the images in the /usr/share tree zoomed to fit 640x480

 feh -g 640x480 -r /usr/share/gnome/help/

same again, but sort by image name before showing.

 feh -rSname /opt/image

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


a random order slide show of images from urls, 30second delay

 cat image-urls | xargs feh -z -D30

useful options
-FZ - full screen and images zoomed to fit
-r - search for all images in a folder tree
-A "rm %f" - delete an image when the 'enter' key is pressed

look at all images on the box, this is ok

 feh -r /

load all images on the computer, sort by size

 feh -S size -r /

Managing Images With Feh ‹↑›

Using 'feh' actions can be linked to certain keystrokes. The action is just a normal bash command.

display images and move the current image when the enter key is pressed

 feh -A "mv %f ~/images/%n" *

show the images in /usr/share tree, delete on 'enter' key

 feh -FZrA "rm %f" /usr/share/

rename images in current folder when enter is pressed

 feh -g620x480 -A 'mv %f $(zenity --entry --text "Rename image")' *.JPG
d a function to examine images and delete when 'enter' is pressed
 vcam() { feh -g640x480 -A "rm %f" /path/to/img/* }

locate all jpegs and copy to a folder when '1' is pressed

 locate -i '/home/mjbishop/*.jpg' | sed 's/^/"/;s/$/"/' | xargs feh -A 'cp %f $(zenity --entry --text "%f")' -dzZF -D5

Thumbnails With Feh ‹↑›

display an enormous montage of all gifs (this is very fast)

 feh -m $(locate '*.gif')

If there are too many gifs, this will fail because the shell (for example, bash) will not be able to deal with so many arguments.

display a thumbnail montage of all gifs in random order (also fast)

 feh -m $(locate '*.gif'|shuf)

display a montage of 200 random 'png' images (quite fast)

 feh -m $(locate '*.png'|shuf|head -200)

create a thumbnail display of 100 random 'png' images, save as 'm.png'

 feh -mO m.png $(locate '*.png'|shuf|head -100); feh m.png

start feh in thumbnail mode with names, click each image to display

 feh -t $(locate '*.png'|shuf|head -100)

Slideshows ‹↑›

A slideshow is a series of images displayed one after another

a big line for rename photos etc, copy to another folders

 locate -i '/home/mjbishop/*.jpg' | sed 's/^/"/;s/$/"/' | xargs feh -A 'n=$(zenity --title "rename image" --entry --text "choose a new name for %f"); n=$(echo $n | tr " " "."); n=$(dirname "%f")/$n.jpg; mv "%f" "$n"; echo "%f renamed to $n"' --action1 'cp "%f" /home/mjbishop/Desktop/photos.febe/; convert "%f" -monitor -resize 700 "/home/mjbishop/Desktop/photos.febe/web.%n"; echo %n copied to photos.febe folder'  --action2 'cp "%f" /home/mjbishop/Desktop/photos.jon/; convert "%f" -monitor -resize 700 "/home/mjbishop/Desktop/photos.jon/web.%n"; echo %n copied to photos.jon folder'  --action3 'cp "%f" /home/mjbishop/Desktop/photos.hamish/; convert "%f" -monitor -resize 700 "/home/mjbishop/Desktop/photos.hamish/web.%n"; echo %n copied to photos.hamish folder' -dzZF -D5

show all 'jpg' files under the Desktop in a fullscreen slideshow

 locate -i '/home/mjbishop/Desktop/*.jpg' | sed 's/^/"/;s/$/"/' | xargs feh -zZF -D3

copy and give a new name when enter is pressed

 locate -i '/home/mjbishop/*.jpg' | sed 's/^/"/;s/$/"/' | xargs feh -A 'cp %f /home/mjbishop/Desktop/photos.febe/$(zenity --entry --text "rename %n")' -dzZF -D5

copy to a folder when the user presses '1' and rename on 'enter'

 locate -i '/home/mjbishop/*.jpg' | sed 's/^/"/;s/$/"/' | xargs feh -A 'cp %f /home/mjbishop/Desktop/photos.febe/$(zenity --entry --text "rename %n")' --action1 'cp "%f" /home/mjbishop/Desktop/photos.febe/; echo %n copied to photos.febe folder' -dzZF -D5

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

Effects ‹↑›

good image magick tips
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

feh options used
z - randomises the order of the slideshow
D5 - makes a delay of 5 seconds between slides
Z - zooms the images to fit
F - full screen

pixelize and image

 convert -sample 10% -sample 1000% input.jpg output.jpg

Creating Pan Animations ‹↑›

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

Education ‹↑›

educational software

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

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

Qiv ‹↑›

appears in active development.

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

[space] - next image
[backspace] - previous

Zgv ‹↑›

view images from a console


the imagemagick image viewer


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


another image viewer


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

The "display" tool can accept image data from 'standard in'

create a montage and display it

 montage $(locate '*.gif'|head -20) -geometry 16x16+1+1 - | display

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

create an html and thumbnail image gallery


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 from the command line.

 ompload() { curl -F file1=@"$1" | awk '/Info:|File:|Thumbnail:|BBCode:/{gsub(/<[^<]*?\/?>/,"");$1=$1;print}'; }

Obtaining Images ‹↑›

Grab all images with the tags 'bitch' and 'bw' from a flickr

   for URL in `wget -O -,bw 2>/dev/null | grep -E -o "http[^ ]+?jpg" | grep -v "_m" | uniq | grep -v 'buddy' `
     FILE=$(echo $URL | grep -E -o "[0-9a-z_]+\.jpg");
     curl $URL > $FILE;

Screenshots ‹↑›

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.

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

take a screen shot in 'tif' format

 scrot -q 10 test.tif

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 ‹↑›

Optimizing Images ‹↑›

optimize png images

 debian: optipng

Image Magick Built In Patterns ‹↑›

a list of all built in patterns which can be referenced as if they were an image

Image Formats ‹↑›

tools for screen capture
import - makes screen shots part of 'imagemagick' package.
scrot - a simple command line screen capture utility
shutter - a graphical prog to take screenshots
screencapture - the macosx (jaguar) utility

Batch Editing Of Images ‹↑›

The term 'batch editing' refers to clipping, rotating, or transforming in any way multiple image files without using a graphical program such as Gimp. The advantage of batch processing of images is that many images can be dealt with quickly and the process can be automated from shell scripts.

lots of usage examples for 'convert' and 'mogrify'
search for software which can batch process (edit) image files
 apt-cache search batch image | less

display a list of packages about image magic and select one to view

 IFS=$'\n';select a in $(apt-cache search image magic); { apt-cache show ${a%% *}; break; }

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

Netpbm ‹↑›

Netpbm is a set of tools to work with files in the formats pbm, pgm, ppm, and pam.

show all files and tools associated with netpbm

 dpkg -L netpbm | less

With the phatch-nautilus function you can access phatch transformations by right clicking the image in the nautilus file manager.

scale and transform images

 mogrify changes the image
 convert doesnt change

Phatch ‹↑›

Can get phatch to work. The files seem unchanged. Documentation not good

show all files which were installed as part of phatch

 dpkg -L phatch | less

show availabe actionlists for phatch

 ls /usr/share/phatch/data/actionlists/

Rounded Corners ‹↑›

A page about rounded borders
put transparent rounded corners on the image magick logo
 convert -size 640x480 xc:none -fill white -draw 'roundRectangle 15,15 624,464 15,15' logo: -compose SrcIn -composite out.png

put a 15 pixel round corner on the logo without knowing its size

 w=$(identify -format '%w' logo:); h=$(identify -format '%h' logo:); convert -size ${w}x${h} xc:none -fill white -draw "roundRectangle 15,15 $(($w-15)),$(($h-15)) 15,15" logo: -compose SrcIn -composite out1.png

the same as above but using a tricky 'eval' to get width and height

 eval "$(identify -format 'w=%w;h=%h' logo:)"; convert -size ${w}x${h} xc:none -fill white -draw "roundRectangle 15,15 $(($w-15)),$(($h-15)) 15,15" logo: -compose SrcIn -composite out2.png

a bash function to put 15 pixel round borders around an image

   rri () {
     eval "$(identify -format 'w=%w;h=%h' $1)";
     convert -size ${w}x${h} xc:none -fill white -draw "roundRectangle 15,15 $(($w-15)),$(($h-15)) 15,15" $1 -compose SrcIn -composite rr.$1

Fancy Effects ‹↑›

put an image on an lcd screen (slow and requires blender)

 phatch -c /usr/share/phatch/data/actionlists/lcd_screen.phatch "$(locate "/home/*.jpg" | head -1)"

Rotations ‹↑›

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

Resizing Images ‹↑›

In this context resizing the image refers to changing the dimensions (as measured in pixels) of an image, rather than changing the file size of the image

tools for batch editing of images
convert - can do lots of things but saves to a new file
mogrify - same as convert but changes the image (but -format ?)
phatch - make rounded corners among other things
phatch-nautilus - integrate phatch with the nautilus file manager
netpbm - lots of tools

reduce in size all jpeg images in the folder by 50%

 mogrify -resize 50% *.jpg    the images are changed

reduce in size jpeg images by 50% and show progress

 mogrify -monitor -resize 50% *.jpg

reduce in size jpeg images to 800 pixels width and show progress

 mogrify -monitor -resize 800 *.jpg

reduce by 50% an image and save the reduced image as "rose2.jpg"

 convert rose.jpg -resize 50% rose2.jpg

resize to 2000 pixles all jpegs wider than 2000 pixels

 for f in *.jpg;{ w=$(identify -format "%w" $f); [ $w -gt 2000 ] && mogrify -monitor -resize 2000 $f;}

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\> *

convert jpegs to ascii


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

Black And White ‹↑›

Create black and white image

 convert -colorspace gray face.jpg gray_face.jpg

Photos Software ‹↑›

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

Animation ‹↑›

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

Creating Animations ‹↑›

tools for resizing images
squash - very basic gui image resizer bad man page
convert -
exactimage - similar to image magic
graphicsmagick - a fork of image magic (uses 'gm' command)
nautilus-image-converter - mass resizing or rotating from nautilus (?)

Animations are really fun, and with imagemagick its simple to create them (without drawing every frame). Combining with other technique simple 'pan' and 'fade-in/fade-out' animations can be created.

convert a whole bunch of jpgs to an animated gif 200x200 showing work

 convert -delay 100 -size 200x200 002[123]*.jpg -loop 0 -monitor test.gif

convert all jpgs to an animation with a 10ms delay which loops

 convert -delay 10 -size 200x200 *.jpg -loop 0 -monitor test.gif

The '-monitor' option is good because it shows what imagemagick is doing and therefore appeases the impatient.

Animated Gifs ‹↑›


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 embedded EXIF text data

 mogrify -format jpg -quality 80 -resize 800 *.jpg

reduce the dimensions by half of the image

 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.jpg  width and height
 convert -trim +repage file.jpg  untested

crop all whitespace from a postscript document and convert to png

 pstoimg -type png -crop a -trans

crop all whitespace from a pdf file and convert to png

 pdftops old.pdf; pstoimg -type png -crop a -trans

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

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 usually the same size.

create a horizontal strip montage "new.gif" resizing to 16x16pxs

 montage $(locate '*.gif'|head -20) -tile x1 -geometry 16x16+1+1 new.gif; display new.gif

The images are laid out "row-wise"

create a horizontal strip montage "new.gif" of 20 random gifs

 montage $(locate '*.gif'|shuf|head -20) -tile x1 -geometry 32x32+1+1 new.gif; display new.gif

create a 2 col 5 row montage, images 16px with 1 pixel spacing

 montage $(locate '*.gif'|head -10) -tile 2x5 -geometry 16x16+1+1 new.gif; display new.gif

create and display a square matrix of images (note standard in piped)

 montage $(locate '*.gif'|head -20) -geometry 16x16+1+1 - | display

If there are not enough images to fill the block, white space is created)

create a 10 column montage, images resized to 16px with 1px spacing

 montage $(locate '*.gif'|head -100) -tile 10x -geometry 16x16 - | display

This takes about 10 seconds on my machine

Montages With Feh ‹↑›

make and display an enormous montage of image in the 'icons' tree

 feh -mr /usr/share/icons/

create a thumbnail montage of the 1st 30 png icons and save as new.png

 feh -mO new.png $(locate '/usr/share/icons/*.png'|head -30);feh new.png

create a thumbnail montage of the 1st 30 jpg icons and save as new.png

 feh -mO new.png $(locate '/home/*.jpg'|head -30);feh new.png

create a thumbnail montage of a random 10 jpg icons and save as new.png

 feh -mO new.jpg $(locate '/home/*.jpg'|shuf|head -10);feh new.jpg

These jpg montages seem to take much longer than png montages

create a thumbnail montage of a random 40 png images

 feh -mO new.png $(locate '/usr/*.png'|shuf|head -40);feh new.png

create a thumbnail montage of 50 png images (found somewhere)

 feh -mO new.png $(locate '*.png'|head -50); feh new.png

create a random overlapping collage of images in the folder

 feh -cO out.png /usr/share/icons/gnome/32x32/apps; xdg-open out.png

create a random collage of images

 feh -cO out.png $(locate '*.png'|head -100); feh out.png

create a random montage of images in the folder tree

 feh -rcO out.png /usr/share/icons/gnome/32x32; xdg-open out.png

create a montage with image information printed under each image

 feh -IO out.png /usr/share/icons/gnome/32x32/apps; feh out.png

create a montage with image information using the 'courier' font

 feh -Ie courier -O out.png -r /usr/share/icons/gnome/32x32/apps

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

Random Montages ‹↑›

create a squarish montage of 60 random gifs, images 32 by 32 pixels

 montage $(locate '*.gif'|shuf|head -60) -geometry 32x32+1+1 new.gif; display new.gif

create a squarish montage of 600 random gifs, images 16x16 pixels

 montage $(locate '*.gif'|shuf|head -600) -geometry 16x16 new.gif; display new.gif   about 30 seconds

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 px spaces, blue background and image shadow

 montage logo: rose: -tile x1 -shadow -geometry 60x60+5+5 -background lightblue out.jpg; display out.jpg

create a 1 row montage putting a 3px bevelled frame around each images

 montage logo: rose: -tile x1 -frame 3 -geometry 100x100+5+5 o.jpg; display o.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 montage with filenames as captions in 10 point courier font

 montage -label '%f' $(locate '*.jpg'|head -10) -font courier -pointsize 10 -geometry 100x100+0+0 out.png; display out.png

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 an overlapped and rotated image montage

 montage null: font_*.gif null: -background none -rotate 30 \
   -background white -tile x1 -geometry -8+2

Galleries And Albums ‹↑›

stills2dv - creates paning animations from still photos
convert - the image magick tool

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 filenote 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 $(find /usr -name '*.jpg' | head -10) -tile 45x -geometry +3+3 o.png; feh o.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

  /usr/bin/printf "\u201Cdouble\u201D" | \
        convert -background lightblue -fill blue -pointsize 36 \
                      label:@-  quotes.gif; feh quotes.gif

 /usr/bin/printf "\u03D5" | convert -fill blue -pointsize 36 label:@- quotes.gif; feh quotes.gif

print some unicode characters

 /usr/bin/printf '\u201cdouble\u201D'

Note that bash has a builtin 'printf' which doesnt do the job, which is why we need /usr/bin/printf

Renaming Images ‹↑›

rename "car.jpg" to something like '23-40pm.3mar2001.jpg'

 exiv2 rename -r "%I-%M%p.%d%b%Y" car.jpg

The filename will be taken from the exif timestamp data.

extract digital camera info from exif jpeg files and rename ?

 jhead -n%Y%m%d-%H%M%S *.jpg

a gtk based image renamer


rename files ending in '.JPG' with '.jpg' even if file has a space in it

 locate '*.JPG' | xargs -I{} rename 's/\.JPG$/.jpg/' "{}"

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


 convert tree.png -gravity south -background LimeGreen -splice 0x15 \

draw text 'tree' in the image in a grey rectangle (superimposed)

 convert logo: -fill '#0008' -draw 'rectangle 5,128,114,145' -fill white -annotate +10+141 'Tree' o.png; display o.png

File Name Captions ‹↑›

write the file name under an image in 30 point courier font

 montage -label '%f' rose: -font courier -pointsize 30 -geometry +0+0 -background silver out.png; display out.png

write the file name under the image, silver background, lots of space

 montage -label '%f' rose: -font courier -pointsize 30 -background silver out.png; display out.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


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.' \
>= 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 ‹↑›

The process of compressing an image refers to reducing the file size of the image. This is particularly important when publishing the image on the internet, on the web, or trying to send the image via email to someone. May email services have a strict file size limitation.

tools for galleries
llgal - a command line gallery generator
webmagick - html galleries
album - html photo album generator

show what optimisation could be done on a set of files, but do nothing

 jpegoptim -n *.jpg

perform lossless compression on a set of jpeg images (usually about 3%)

 jpegoptim  *.jpg

show what compression would be done reducing quality to 40%

 jpegoptim -m40 -n *.jpg | less

display the total file size of files in this folder

 du -sh

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

 convert tree.jpg -quality 80% tree-80.jpg

reduce the quality, showing progress

 convert '1332.jpg~' -monitor -quality 60% z.jpg

print jpeg image file sizes and filename

 identify -format "%b %f\n" *.jpg

print jpeg image file sizes

 identify -format "%b\n" *.jpg

reduce in quality jpeg files bigger than 2 megabytes

 for f in *.jpg;{ w=$(identify -format "%b" $f); [ $w -gt 2000000 ] && mogrify -monitor -quality 80% $f;}

calculate and reduce to 200K size an image file, save as 'new.jpg'

 f=1326.jpg; s=$(echo "scale=0; 200000*100/$(identify -format "%b" $f)" | bc -l); convert $f -monitor -quality ${s}% new.jpg

the same but better

 for f in *.jpg; { s=$((500000*100/$(identify -format "%b" $f))); echo $s; convert $f -monitor -quality ${s}% web.$f ; }

calculate and reduce to 350K size a set of jpeg images

 for f in *.jpg; { s=$(echo "scale=0; 350000*100/$(identify -format "%b" $f)" | bc -l); convert $f -monitor -quality ${s}% web.$f ; }

The -quality function will reduce the file size by the stated percentage This seems better visually than resizing the jpeg.

reduce a jpeg even more

  -sampling-factor 2x1

Reducing the dimensions of an image can also reduce its file size

reduce in size all jpeg images to 1500 pixels width and show progress

 mogrify -monitor -resize 1500 *.jpg

reduce the dimensions of an image by 50% and save as "r.jpg"

 convert rose.jpg -resize 50% r.jpg

resize to 2000 pixles all jpegs wider than 2000 pixels

 for f in *.jpg;{ w=$(identify -format "%w" $f); [ $w -gt 2000 ] && mogrify -monitor -resize 2000 $f;}

Resizing jpegs is not very good, it makes everything fuzzy.

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 ‹↑›

www: deb:
grokking-the-gimp a book about using gimp
xmorph, gimp

a simple paint program


edit bitmaps, pixmaps

 tkpaint, bitmap

Three D Image Editors ‹↑›

sced, moonlight

Comic Strips ‹↑›

tools to reduce image file size
pngquant - use a slightly lossy compression technique
pngcrush - increase png compression
pngnq - quantise png images
optipng - optimise png
jpegoptim - utility to optimize jpeg files overwriting

list available comic strips

 dailystrips --list

download todays dilbert cartoon and view it

 dailystrips dilbert > dilbert.html; xdg-open dilbert.html

download the dilbert cartoon image included

 dailystrips -l dilbert

Visual Art ‹↑›

Image Repositories ‹↑›

The open clip art library.

a tag cloud of open clip art
comic strip tools
dailystrips - allow convenient viewing of comic strips

Ascii Images ‹↑›

a demonstration of the aview tool


create-resources - brushes gradients etc

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

convert a random jpeg to ascii

 locate *.jpg|shuf|head -1| xargs jp2a

view a video using only 'ascii art'

 mplayer -vo aa <video file>

bulk dl files based on a pattern

 curl -O /met-art-free-sample-00[00-19].jpg

Converting To Ascii ‹↑›

convert and print i.jpg using ascii chars in 40 columns and 20 rows

  jp2a --size=40x20 i.jpg

download an image off the net, convert and print


output p.jpg and q.jpg, each 80x25 chars, using the chars " ...ooxx
www: ">"
 jp2a --size=80x25 --chars=" ...ooxx 
www: "
p.jpg q.jpg
output i.jpg in 76 columns, height automatically calculated
 cat i.jpg | jp2a --width=76 -

use jp2a with ImageMagick convert with pipes

 convert somefile.png jpg:- | jp2a - --width=80

convert a random png file to ascii

 convert $(locate *.png|shuf|head -1) jpg:- | jp2a - --width=75

convert a random jpg with 'mjb' to ascii, width 75 character

 jp2a --width=75 $(locate *mjb*.jpg|shuf|head -1)

create an html pre tag with an ascii image

   (echo "<small><small><pre>";
   jp2a --width=300 $(locate *mjb*.jpg|shuf|head -1);
   echo "</pre></small></small>";) > test.html

Patterns And Tilings ‹↑›


Jpeg Images ‹↑›

ascii art tools
aview -
jp2a - converts jpegs to ascii
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

convert 'in.jpg' to ascii 40 columns by 20 rows and display

 jp2a --size=40x20 in.jpg

Svg Scalable Vector Graphics ‹↑›

This is an important topic which will need to be expanded.

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

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 Optical Character Recognition or 'ocr'. This is useful because textual data can be saved using much less memory than image data, and because text files may be searched for words or phrases, but images no.

look for ubuntu/debian packages for text recognition

 sudo apt-cache search ocr

jpeg tools
cjpeg -
jp2a - convert jpegs to ascii
djpeg -
jpegtran -
convert - the image magick tool

Ocropus ‹↑›

Ocropus builds apon the capabilities of tesseract by adding layout analysis (multicolumn text, boxed text etc). The ocropus man page is very terse.

analyse an image file 'page.png' and extract the text saving as html

 ocroscript rec-tess page.png > page.html

take a screen shot of the terminal and run ocropus on it

 scrot test.png; ocroscript rec-tess test.png > page.html

show what scripts are available to use with ocropus

 ls /usr/share/ocropus/scripts/

select an ocropus script to examine

 select f in /usr/share/ocropus/scripts/*; { less $f; break; }

optical character recognition ('ocr') tools
tesseract - command line ocr tool developed by hp, no layout analysis
ocropus - a google sponsored ocr tool can use 'tesseract'
gocr - slightly patchy tool still in development
ocrad - gnu software seems to handle unicode text (utf8)
clara -
unpaper - improve the quality of scanned text images

Tesseract ‹↑›

This ocr tool was developed by HP and then open-sourced. It cannot handle multi-column text but is able to recognise characters well. The image should be of black and white text in one column and should be in uncompressed 'tiff' format.

install tesseract and data for the english character set

 sudo apt-get install tesseract-ocr tesseract-ocr-eng

Tesseract by default only seems to install data for the german character-set

see what language character sets are already installed for tesseract

 ls /usr/share/tesseract-ocr/tessdata/*.unicharset

see what language data sets are available for tesseract

 sudo apt-cache search tesseract

analyse the 'page.tif' image and store text in 'result.txt'

 tesseract page.tif result

produces good results from a screen shot, by converting to black and white

 scrot test.tif; mogrify -colors 2 test.tif; tesseract test.tif out

produces bad results (because of 'monochrome')

 scrot test.tif; mogrify -monochrome test.tif; tesseract test.tif out

Notes ‹↑›

netpbm, pamcut, pnmtotiff are these useful tools ?


what the ocropus scripts do
degrade.lua - simple document image degradation
hocr-to-text.lua - convert hocr output to plain text.
line-clean.lua - given a line image remove noise and other problems.
sauvola.lua - Perform Sauvola thresholding.