Sunday, February 14, 2010

Feeding images to a digital picture frame

My digital picture frame has a limited amount of build in memory. In order to put more pictures on the frame, I choose to resize them to the frame's native resolution of 800x480.

I' m pretty sure that there are applications that manage image collections on Linux and also do image resizing. However, I prefered to use ImageMagic and some scripting to do the job.

My script, dir2w820.sh, takes files from a source directory. These may be images and videos mixed together. Then it resizes JPEG files and copies all others (possibly videos) to the current directory. The target resolution for the images is hard coded to 800x480 in the script, but changing this is trivial.

Here is a usage example. We have the original folder as taken from the digital camera in 'camera' and a destination folder 'picture_frame' that will consist of the contents to place on the frame.

$ ls
camera/ picture_frame/
$ cd picture_frame
$ dir2w820.sh ../camera/*

... when done, you can browse through picture_frame to see the result.

dir2w820.sh:


#!/bin/tcsh
#
#
# Written by Michalis Giannakidis - 2009 -
#
# Released in the public domain as is, without any warranties. Feb 2010
#

set resolution="800x400"

if ( $# == 0 ) then
echo "Convert images to $resolution and copy to current directory."
echo "usage: `basename $0` source_files"
echo "example: `basename $0` ../original/*"
echo "Current directory needs to be different than the source."
exit
endif

set counter = 0

foreach i ( $* )
set counter = `expr $counter + 1`

set bfile = `basename $i`
set bdest = `python -c 'import sys; print sys.argv[1].decode("utf-8").lower().encode("utf-8"),' $bfile`

if ( -f s_$bdest || -f $bfile || -f s_$bfile ) then
echo $counter/$# s_$bdest exists. I refuse to copy.
continue
endif

file $i |grep -q "JPEG image data"
if ( $status == 0 ) then
echo $counter/$# s_$bdest
convert $i -resize $resolution^ -gravity center -extent $resolution s_$bdest
else
echo $counter/$# $bdest copied.
cp -f $i $bdest
endif

end

No comments: