— my toolbox is filled with perl, javascript, css and html


How to deliver your images through Cloudinary with Perl

Tuesday, July 10, 2012

Cloudinary is a cloud-based service for image management & manipulation. From their about page:

Use Cloudinary to:

I personally feel that Cloudinary has lifted a burden from me, since I really don’t like to figure out the best Perl module to manipulate my images. I used to use Imagemagic for a while, but it simply isn’t that easy to use as Cloudinary.

I started out with the excellent documentation, discussed with Cloudinary using their online chat, and managed to pull together a Perl module I named Cloudinary. This module is based on top of the excellent Mojolicious framework, which allow you to communicate with Cloudinary in an async matter, which can be useful if you’re working with a lot of assets.

Main features


To run the examples below, you need to install the module first:

cpanm -n --sudo Cloudinary

Don’t have cpanm? Install cpanm using this command:

curl -L http://cpanmin.us | perl - --self-upgrade

So how do you talk with Cloudinary? Here is an simple example which doesn’t even require an account:

use feature 'say';
use Mojo::Base; # or strict and warnings;
use Cloudinary;

my $cloudinary = Cloudinary->new(cloud_name => 'demo');
say $cloudinary->url_for('jhthorsen.jpg' => {
        type => 'facebook',
        width => 50,
        height => 100,

The code above will print this URL, which points to a scaled Facebook image of me:


The destribution also includes a Mojolicious plugin which provide helpers which makes embedding images in your mojo templates easy:

%= cloudinary_image 'jhthorsen.jpg', { type => 'facebook' };

The above code will produce this output:


Try it out!

Register a free plan at Cloudinary try it out for your self. My module should allow you to take advantage of all the cool transformations which Cloudinary provides – and if not: Create an issue or send me a pull request on github.

More information can be found on metacpan:

Enjoy :)

blog comments powered by Disqus