Jun
17
WebifyImages.pm – My Image Editing Scripts (v0.2)
Filed Under Computers & Tech, Software Development, Photography on June 17, 2012 at 5:47 pm
Yesterday I posted my thoughts on watermarking images for uploading to the web. This post formed the basis of myself and Allison Sheridan’s discussions in the Chit Chat Across the Pond segment on tonight’s Nosillacast Mac Podcast. During the discussion we talked a little about how I watermark my images, and I realised that I hadn’t released a version of my image processing scripts since 2008! I promised I’d remedy that, so today, after a little tidying up, I’m releasing the current snapshot of my scripts under the FreeBSD license.
I’m not releasing these scripts as a polished software package that’s ready to use, but rather, as a starting point for anyone who wants to create their own watermarking scripts. If you’re not prepared to get stuck into the command line and a little Perl (VERY little is needed mind), these scripts are of no use to you!
The scripts rely on the free and open source ImageMagick command line image editing tools, so you’ll need to install ImageMagick before you get stuck in. If you’re running OS X, I’d recommend installing ImageMagick via the free and open source MacPorts package manager.
All the core functionality provided by the scripts is contained within a single perl package, WebifyImages.pm
. Any customisations you want to make to the watermarks will need to be made here. The code is well commented, but, unfortunately, it dates back to before my conversion to the Perl Best Practices religion, so it barfs out an embarrassing number of warnings when run through perlcritic
. I do plan to re-write it some day, and when I do I’ll be making it object orienting, and ensuring that, like all my recently written code, it passes perlcritic
.
All command line interactions with the functionality contained within WebifyImages.pm
is accessed through the perl script webifyFn.pl
. Once you have the scripts up and running, you should never have to edit this file, it really is just a wrapper. If you add any new functions to WebifyImages.pm
you’ll need to be sure to add an entry for them into the $WebifyImages::functions
hashtable or they won’t be accessible via webifyFn.pl
.
Installing the Scripts
I haven’t written an installer script, so you’ll have to do a little work by hand here. Again, don’t even bother starting with this until you have ImageMagic installed, and know where on your system the binaries for it are located. If you follow my advice and ImageMagick install via MacPorts, the binaries will be located in /opt/local/bin/
. If you want to check where they are located, just run:
which mogrify
This should return something like:
bart-imac:~ bart$ which mogrify /opt/local/bin/mogrify bart-imac:~ bart$
This shows that my ImageMagick binaries are indeed in /opt/local/bin/
.
- Unzip the download package, and copy it’s contents to a folder of your choice on your system. I recommend something like
~/scripts/webifyImages/
(where~
is your home directory) - Open the file
WebifyImages.pm
and make the following edits:- Set the value of
$WebifyImages::HOMEDIR
to the location you extracted the zip to. If you used my suggested installation location, you won’t need to make any changes here. - Set the value of
$WebifyImages::IMAGEMAGICK_BIN
to the location where your ImageMagick binaries are installed.
- Set the value of
- Open the file
webifyFn.pl
and edit theuse lib
directive on line 33 so that it contains the absolute path to the folder whereWebifyImages.pm
is located. - If your OS’s copy of Perl is not located at
/usr/bin/perl
, you’ll need to edit the first line of bothWebifyImages.pm
andwebifyFn.pl
to reflect the path to your instance of Perl. (this location is the default on OS X and most versions of Linux, so you probably won’t need to change this)
Customising the Scripts
The first thing you’ll want to do is create your own versions of the image files containing the URL that will be stamped on the images. You’ll need to do two versions of your image file, one on a white background, and one on a black one. I’ve included the Pixelmator files I used to generate my image files in the dev
folder inside the archive, if you’re a Pixelmator user you might find them helpful. Once you’ve created your own image files and saved them somewhere, update the values of the variables $WebifyImages::URL_ICON_ONWHITE
and $WebifyImages::URL_ICON_ONBLACK
in WebifyImages.pm
with the new file paths.
Once you’ve done that you’ll also need to update the URLs in the functions insertUrl()
and insertSemiTransparentUrl()
on lines 224 and 236 of WebifyImages.pm
.
At this stage you’re ready to start using the scripts, but you may want to do some more customisation.
If you want to change the fonts used by the scripts, you can edit the variables $WebifyImages::SCRIPT_FONT
, $WebifyImages::SANSSERIF_FONT
, and $WebifyImages::CAPS_FONT
in WebifyImages.pm
.
If you use a license other than Creative Commons Non-Commercial, Non-Derivative, Attribution, then you’ll need to create your own image file to represent that license (or download a different CC icon from the Creative Commons site if you are using a different flavour of CC), and edit the variable $WebifyImages::CC_ICON
in WebifyImages.pm
with the path to your image.
Using The Scripts
The first thing to make VERY clear is that THESE SCRIPTS ALTER THE IMAGES THEY ARE APPLIED TO. They are designed to be used on images exported from an image management package like Aperture or Lightroom, and are NOT designed to be used on your master images!
You apply the functionality contained in WebifyImages.pm
to images by changing to the directory containing the images in the terminal, and then invoking webifyFn.pl
on those images. To make things easier you probably want to add the folder you installed the scripts into to your path. The webifyFn.pl script is invoked in the following way:
webifyFn.pl [function_name] [function_arguments]
To get a list of available functions, and a description of the arguments they expect, run:
webifyFn.pl list
That really is all there is to it – you can just use my scripts as they are (with your basic customisations obviously), or you can tinker and edit to your heart’s content!
[…] #371 Verizon Mifi Jetpack 4G, Cobooks, Flame Virus for Windows, Image Watermarking By podfeet on 17 June 2012 Bart answers Steve’s question about why the cosmos forms in a disk before spinning. I review Verizon’s latest Mifi offering, the new Jetpack 4G. I review the Address book alternative Cobooks from cobookapp.com. In Security Lite Bart explains the importance of the Flame virus, and then in Chit Chat Across the Pond he talks through the thought process you might want to consider in whether or not to watermark your images before posting on line and how he goes about doing it. Mark Pouley and Allister Jenks both recommend the donationware plugin BorderFX iborderfx.com, or you can check out Bart’s AppleScripts for watermarking at bartb.ie. […]
[…] WebifyImages.pm – My Image Editing Scripts (v0.2) […]
[…] Update (18 June 2012) – A more up-to-date version of these scripts can now be found here. […]
[…] 24 June 2012 Bart’s newly revamped scripts to watermark images are now available at bartb.ie under the FreeBSD license, my thoughts on the two new Microsoft Surface tablets. In Dumb Question […]
Getting some cool effects here. Thanks.
FYI: Here are some more detailed installations if you are starting from a vanilla system (i.e. no MacPorts or Xcode)
1. Create directory “/opt/local” using “sudo”
a. Cd /
b. Sudo mkdir /opt/local
2. Install Xcode from app store
3. Start up Xcode
4. Open Xcode Preferences and select Downloads tab.
5. Locate “Command Line Tools” and click on “Install”
6. Go to Bart’s website.
7. Follow the link to ImageMagick website, using a new tab in your browser.
8. On left side, under “Binary Releases”, click on “Mac OS X”.
9. Follow link to MacPorts.org to install MacPorts, using a new tab.
10. On left side, click on “Installing MacPorts”
11. Follow instructions on installing MacPorts. MacPorts is installed under /opt/local
a. Click on “Lion” in text and download MacPorts package.
b. Install package
12. Return to ImageMagick website tab and follow instructions to install ImageMagick (which also installs under /opt/local)
13. Do installation test from a terminal. This verifies the command line environment is set correctly. MacPorts should do most of the setup for you. You might need to open a new terminal window.
14. Unpack & install Bart’s WebifyImages scripts. He put his in ~/scripts. I put mine in ~/Applications.
15. Follow his instructions to install and customize. Search for “bartb†in WebifyImages.pm for other places to customize.
[…] geraumer Zeit einmal einen sehr guten Artikel zur Wasserzeichen-Frage verfasst und dort auch ein sehr nützliches Perl-Script veröffentlicht, mit dem man ebenfalls Wasserzeichen in viele Bilder gleichzeitig einfügen kann. […]