Aug
30
My Perl Image Processing Scripts
Filed Under Computers & Tech, Software Development, Photography, My Projects on August 30, 2008 at 8:00 pm
Update (18 June 2012) – A more up-to-date version of these scripts can now be found here.
My Myers Briggs personality profile insists that I “prefer economy of effort”, you can probably translate that to “is a lazy sod”. Because of this I like automating repetitive tasks. It all started when I wanted a quick and easy way to prepare my images for posting to my website. I wanted them resized with my URL and the Creative Commons icon added in, and I wanted to be able to process a whole directory of images in one go. I started by playing around with the GD libs in PHP, but soon realised it would be quicker and easier to use Perl to shell out to the command line tools from Image Magick. At the time I wrote a post on my choice to do this which also contained the initial code. That code has been expanded and evolved since, and now includes functions for rendering nice (in my opinion) borders and titles on my better images. If you want to see examples checkout the Photo of the Week category on this blog..
[tags]Perl, Image Magick, script, programming, image processing[/tags]
I’m releasing my collection of scripts under the GPL today but they come with some warnings. This is a collection of scripts I write for my personal use. They are not packaged in a generic way, there is no installer, and they’re far from fool proof. Rather than being a finished product look at them as a starting point for creating your own scripts to help you automate the tasks you need to do with your photographs. I wasn’t planning on publishing them at all, but people keep asking me what I use for batch processing my images, and when I tell them I’ve written my own scripts, they all want to see how it’s done. Also, these are straight from my personal SVN repository without any edits. I just stuck them into a zip along with a copy of the GPL and posted the resulting zip file here. Luckily for you I’m quite fond of commenting my code, and apparently I write very legible Perl.
The zip contains a Perl module with the core code (WebifyImages.pm
), a collection of Perl scripts to apply the functionality in various ways and combinations (the .pl
files), and the two needed support files (the Creative Commons icon, and the .ttf
file for the font I use).
In order to use these scripts you need to do four things:
- Install Image Magick on your machine and make sure the binaries are in your path (this might help). These scripts all use the Image Magick binaries so they’re useless if you don’t do this!
- copy all the files in the zip into a folder somewhere on your machine. Then edit all the
.pl
files so that theuse lib
line near the top reflects the path you just copied the files to. For example, I store the files in/Users/bart/scripts/webifyImages
, so I have theuse lib
line set to:use lib '/Users/bart/scripts/webifyImages';
. If you don’t do this the perl scripts won’t work from any folder other than the one you copied the files to. - You need to add the folder with the scripts to your path. On OS X you do this by editing the file
~/.bash_profile
(you may have to crate it) and inserting a line something like:export PATH=$PATH:/Users/bart/scripts/webifyImages
. If you don’t do this you’ll have to use the full path to the scripts all the time. - You need to change the URL in the function
insertUrl
in the filewebifyImages.pm
or you’ll be crediting me with all your work! Depending on the Creative Commons license you want to use you may also have to replace the filecc80x15.png
to the correct one for your chosen license. I use quite a restrictive CC license for my images. If you want to use a file with a different name you’ll have to edit the value of the variable$WebifyImages::CC_ICON
which is set near the top ofwebifyImages.pm
.
At this stage you’ll be able to use the scripts, but the chances are you’ll want to edit them to give your photos your own look and feel.
These scripts are not without issues. I’m aware that they have a problem with spaces in file names, & symbols in file names and ‘ symbols in captions, titles etc.. There’s a good chance they have other issues too but I haven’t found those yet.
Finally, if you’ve never programmed before you might be interested in having a look inside the files. You might be surprised at how ‘Englishy’ scripts can be, even Perl scripts which have a reputation for being totally illegible to all but trained super code ninjas 🙂
Bart
Well done on releasing free software!
Although I think the GPL covers yer arse in case the software doesn’t work, I think it’s great to see you writing an explanation anyway. It’s like a fine personal touch.
Paul
Oh… also just in case ye forgot, maybe though the download onto your website:
http://www.bartbusschots.ie/downloads.php
and link to this blog post…
… just a thought
Cheers Paul, good point about the downloads page. Mind you, that whole site is horribly out of date. I’ve been meaning to move it into wordpress for ages now. Really should do that.
Bart.
This is a good implementation, I like develop in C so much, and this is a first idea to insert a Image’s Handler in my apps.
Very Thanks 🙂
[…] written my own Perl scripts which use the ImageMagick command line image editing tools to automate the creation of my […]
[…] written my own Perl scripts which use the ImageMagick command line image editing tools to automate the creation of my […]