8Nov04 Photo workflow with ImageMagick
Most recently I was helping a friend of mine putting together a small photo gallery for a site. I had the photos that needed to be put in place but they needed to be resized into a smaller size and thumbnail size. Instead of using Photoshop, I used the command line applications that are part of ImageMagick since they are faster and produce acceptable results when working with a large set of images.
Converting images
convert allows you to take an image file and process it. In this example, we loop through the .jpg files in a directory and convert each file into an image that is 40% smaller. The resulting image is saved to the "thumbs" directory with the same filename.
for img in 'ls *.jpg'
do
convert -sample 40%x40% $img thumbs/$img
done
Getting image information
identify describes the format and characteristics of one or more image file. In the following example, I am building the img tag for each image and appending it to the photo_info.txt file. For more information about the format string, please check the documentation.
for img in 'ls *.jpg'
do
identify -format "<img src=X%fX width=X%wX height=X%hX alt=X%fX>" $img >> photo_info.txt
done
In the case above, I am using X
instead of using quotes (") for the image tag attributes. Once I had the bulk of information, I used my text editor to do a find/replace and format the information appropriately.
Comments are closed.