|There's more than one way to do things|
Recursive image processing (with ImageMagic)by wvick (Novice)
|on Nov 22, 2012 at 20:50 UTC||Need Help??|
wvick has asked for the
wisdom of the Perl Monks concerning the following question:
Newbie in the house! It's been about 5 years since I did any Perl but I've just been handed a problem which I suspect can be solved elegantly using a relatively short script.
I have a directory which contains other directories - some containing and a large (millions!) number of small PNG images. I need to make a copy of this directory structure into a new location, with all the images converted to greyscale. Yes, grey. I'm British and so am allowed to spell it like that. :-) The utility needs to run on a Windows platform.
I've already pre-selected ImageMagick to do the image processing and was originaly going to write a C/C++ program to do the job. However, when I noticed that ImageMagick has a Perl module, I started to recall that Perl has some nice built-in file system management which can be expressed concisely. I'm also aware there are a lot of modules out there which can do some clever things and save a lot of effort.
So, I'm looking at a utility which accepts a source directory and target directory as parameters. It will then scan through the source directory, recursing into sub-directories, and scan for PNG images. When it finds one, let PerlMagick do the hard work and write the output. Of course, I also need to create sub-directories on the output folder.
I wondered if anyone had created (something like) a recursive file copier which I could adapt to a recursive image processor? Alternatively, any help/guidance on the directory scanning and recursion would be appreciated, especially given the number of PNG images being processed (in each folder and overall). TIA.