using make to convert images to thumbs
Jason Stephenson
jason at sigio.com
Sun Feb 26 10:54:01 EST 2006
Python wrote:
> I have a client that laid out their images and thumbs into almost
> parallel directory structures.
> /img /thumb
> /x /img
> /y /x
> /*.jpg /y
> /*.jpg
>
> x and y are two digit directory names used to shorten the directory
> scans to retrieve files. I thought I could use a Makefile to automate
> the creation of thumbs, but this pattern has me stumped.
How so? It is very straightforward. I'd put the Makefile in the /img
directory or just above it. Your target to make the thumbnails would run
whatever program makes the thumbnails with the appropriate options.
If you needed different target directories, you could specify them in
the environment and on the command line. BSD make makes this trivial and
I'm pretty sure that GNU Make works about the same.
Here's an example:
The Makefile:
## Makefile example starts here. ##
IMG_BASE = /img
THM_BASE = /thumb/img
IMG_PROC = /path/to/image/processor
IMG_PROC_OPTS = # default options for image processor
TARGET = # undefined. define on command line
thumbs:
if test "${TARGET}" = "" ; then
echo "TARGET undefined"
else
${IMG_PROC} ${IMG_PROC_OPTS} ${IMG_BASE}/${TARGET} \
${THM_BASE}/${TARGET}
fi
## Makefile example ends here. ##
Then, on the command line, you might run:
$ make thumbs TARGET=x/y
The above should work with BSD make, and I'm 90% certain that it will
work with GNU make, as well. It might require a little massage to
actually do anything useful.
>
> I am going to just write a script to step through the source tree and
> check the corresponding time stamp unless someone offers a suggestion.
> (No they will not shuffle things around because they have lots of logic
> in place.)
That would work if you have it run periodically and just make thumbs for
new files, or files that have changed. My example above could be used to
do entire subdirectories at once.
If you know much about make, there are ways to make the above fancier
and more bulletproof. For instance, you might want to have IMG_PROC_OPTS
be added to what is specified in the environment rather just being
hardcoded in the Makefile or completely overridden by the command line
environment. This would make it easier to have slightly different
options on a given run.
Also, if you need to specify filenames or globs to the IMG_PROC, you can
do that as part of your target. My assumption above is that the IMG_PROC
can take directories as targets and processess everything in
them.--Perhaps it is a script.
Along the same lines, a fancier solution would run a shell loop over the
files in the TARGET directory, and process each one with IMG_PROC if you
don't have a script to do everything in a directory in one go.
HtH,
Jason
More information about the gnhlug-discuss
mailing list