Cloudinary Blog

Cloudinary's jQuery plugin for embedding and transforming images

by Itai Lahan
As web developers, we closely monitor the shifts in today's modern web applications architecture stack. We find the client vs. server-side HTML rendering debate particularly interesting.
In the past several years, we’ve witnessed the enormous rise in popularity of client-side JS/CoffeeScript MVC & MVVM solutions. From popular libraries such as Backbone.js that strive to add basic structure to client-side apps, all the way to feature-rich libraries that manage your entire client-side stack, with data-binding, client-server model sync, dependency tracking, templates and more. The involvement of high-profile companies and individuals in this market is also fascinating, between KnockoutJS contributions from Microsoft, the Google-backed Angular and Yehuda Katz's Ember, the heat is definitely on. 
Client-side rendering adoption will most likely continue to grow as major companies adopt the concept and treat the browser as just another device to access their server-based APIs. Twitter is one of these companies. Twitter's engineers has moved to client-side rendering a year and a half ago as part of their last major redesign work. They even went a step further and open sourced their entire Javscript toolbelt as part of the Bootstrap project.
Since we at Cloudinary have been longtime fans of server-side rendering, the first web application development framework we've integrated Cloudinary with was Ruby-on-Rails. 
Due to popular demand, we really wanted to help simplify image management for Javascript developers - client-side rendering and node.js developers alike. Fortunately, Cloudinary’s techniques are already based on simple URL and HTTP interfaces that can be easily integrated with any web-dev framework.
Without further ado, we want to introduce Cloudinary’s jQuery plugin. It is open-source and available at GitHub.
We have big plans for this jQuery plugin. We’ll tell you more about it in the follow-up posts. In the meantime, we wanted to show you how to easily integrate Cloudinary for embedding images and transforming images using Javascript.
For example, a JPG file was uploaded to Cloudinary and was assigned the 'sample' public ID.
First, configure your cloud name:
$.cloudinary.config("cloud_name", "your_cloud_name_goes_here");
The following Javascript command returns the URL of a 150x100 transformed version of the uploaded image:
                 { width: 150, height: 100,
                   crop: 'fill', gravity: 'south'});
It returns the following Cloudinary URL that goes through AWS CloudFront CDN. Note that 'demo' should be replaced with your Cloudinary's cloud name.

Cloudinary's jQuery plugin includes the 'image' function. It returns an IMG HTML element that you can add to your page.
The following example generates a 150x100 PNG version of the uploaded image, this time with rounded corners. It also generated an IMG tag and adds it to the HTML DOM elements with the 'image_holder' class:
                        { width: 150, height: 100,
                          crop: 'fill', gravity: 'south', radius: 20}

This would generate the following HTML elements:
<div class="image_holder">
  <img width="150" height="100" class="my_class_name"   

You can use the same method to create an image tag with a Facebook profile picture. Simply specify the user's Facebook name, fan page name or numeric ID and the required format.
For example, the following Javascript commands returns Cristiano Ronaldo's Facebook profile picture. Using Cloudinary's image transformations, the picture is cropped to a face detection based thumbnail of 80x100 pixels.
                    { width: 80, height: 100,
                      crop: 'thumb', gravity: 'face'});

See our documentation of Facebook & Twitter profile picture for more details.
Note: '$' in all examples can be replaced with ‘jQuery’.
Another useful thing you can do with the jQuery plugin is lazy loading of images and resizing on demand and on the fly. 
For example, add the following image tag to your HTML:
<img src="blank.png" class="dynamic_image”"
     data-width="115" data-height="135
     data-crop="thumb" data-gravity="faces" data-radius="20"/>
It points to a placeholder 'blank.png' image, but the actual image is 'couple.jpg'. 'couple' is a public ID of an image previously uploaded to Cloudinary. All attributes starting with 'data-' are parameters to Cloudinary's image transformation engine.
Simply running 'cloudinary' on a given jQuery selector would process all images matching the given selector. The following example processes all elements with the dynamic_image class when the document is ready:
$(document).ready(function() {
This would automatically generate transformed versions on the fly. In this example, a 115x135 rounded-cornered thumbnail based on face detection. The transformed image is delivered through a fast CDN. The IMG tag would be converted to the following and the requested image would be displayed:
<img src="
     width="115" height="135" class="dynamic_image"/>

What do you think? We would love to hear your feedback on our jQuery plugin and your ideas for enhancements. We are already working on some cool additions, we would update you soon...

Recent Blog Posts

How to generate waveform images from audio files

by Meir Feinberg
How to generate waveform images from audio files

Many social networks, websites and messaging applications allow users to upload a wide variety of media files, and although the majority of files are in the form of images and video clips, a significant minority are audio files. When the website or application subsequently needs to display a thumbnail that describes the uploaded content, images can be cropped and resized down to scale, and a single frame from a video clip can be converted to an image and then also cropped and resized down to scale.

Read more
5 ways to optimize images for effective social sharing

As a website/app developer or owner, you’ve undoubtedly experienced your fair share of glitches and mishaps when it comes to users or site visitors sharing your content. Many outlets such as news and media sites, social networks, or e-commerce sites include the option to "like" or "share" content such as blog posts or images. Once shared, the social network site displays a snippet of the shared content alongside a featured image. This way, your site content gets maximum exposure in social networks and attracts additional visitors.

Read more
Google's new logo might not be as small as claimed

The Internet was abuzz last week after the announcement of Google’s new logo. What caught our eyes more than the artistic changes was this sentence on Google's blog: "building a special variant of our full-color logo that is only 305 bytes, compared to our existing logo at ~14,000 bytes". Sounds exciting! But is it correct?

Read more
Transcode, convert, resize, crop and manipulate videos

Videos are becoming more prolific with people having the capability to capture videos with a wide variety of cameras, including smartphone cameras that are available almost everywhere. Web and mobile applications that display videos online can be faced with a challenge when the videos are created or uploaded from different devices and in various formats, and then need to be delivered in a multitude of resolutions and aspect ratios to various web browsers, laptops and all kinds of mobile devices in HTML5 web friendly video formats.

Read more

Taking the labor out of baby books

by Nicole Amsler
How Baby's Firsts save development time with Cloudinary
Cloudinary helps Baby’s Firsts App deliver images quickly and preserve consistency from app to print. Baby’s Firsts is a free iPhone app that helps parents collect photos, instantly share photos via Facebook, Twitter and Flickr, and produce photo albums of their baby’s first year. Using more than 300 creative, developmentally timed reminders to capture key moments and milestones, the easy-to-navigate app enables parents to store photos in the cloud and create customized photo pages that are then transformed into heirloom-quality, printed baby books. 
Read more