Cloudinary Blog

Display Instagram and Google+ profile pictures in your website and mobile app

by Nadav Soferman
Embed Instagram, Google+ profile pictures in your site
Many modern web and mobile applications include integral social aspects as parts of their online solution. 
 
Users can sign-in to these services and be identified by their chosen social identity. This is made quite straightforward by leveraging single sign-on services such as Facebook Connect, Twitter, Google+ and others. After signing in, activities in the service and user generated content can be accompanied with the real name of the users as well as their profile pictures.
 
In order to display a user's social profile picture in your web site, you'll need to support all the different APIs provided by the relevant social network, each with its own quirks. You'll then probably want to fetch the profile picture to your local server. After that, you'll want to modify the picture to match your graphic design's dimensions and aspect ratio requirements, apply the relevant transformations (applying circular crops, sharpening, etc.), and remember to update the images on your side when users update their profile pictures on the social network.
 
Overall, a lot of small things to take care of.
 
Fortunately, Cloudinary already does all that for you. Simply specify the social profile name or ID using Cloudinary's dynamic image URLs and you're done. Cloudinary contacts the social network and automatically fetches the profile picture that best matches your display requirements. It then transforms the image on-the-fly to match your graphic design, delivers the image optimized and cached through a fast CDN and refreshes the image periodically in case it was changes on the social network.
 
This blog post details how you can embed social pictures from Google+ and Instagram, our latest additions to Cloudinary's list of supported social networks (adding to Facebook, Twitter and Gravatar).
 

Instagram profile pictures

Every Instagram user has a unique public user name and a main profile picture. If you know that a piece of content on your site was contributed by a certain Instagram user, you can use Cloudinary's delivery URLs to fetch and display their main profile picture side-by-side with their added content.
 
The following example fetches the profile picture of 'angelinajolieofficial' while transforming it to fill a 120x120 rectangle, optimizes it and delivers it through a CDN.
 
 
120x120 Instagram profile picture
 
If you use one of our client libraries, all you need to do is to set the image type to 'instagram_name'. Here's a Ruby on Rails example:
<%= cl_image_tag('angelinajolieofficial.jpg',
                 :type => :instagram_name, :width => 120, :height => 120, 
                 :crop => :fill) %>
In the example above, the original Instagram profile picture was displayed while reducing its original dimensions. You can apply any Cloudinary transformation on-the-fly to match the look & feel of your application on any desktop, mobile or retina display. The following example generates a 90x90 circular crop thumbnail of the same photo. Automatic face detection was used to correctly crop the original image. In addition, an automatic image improvement filter was applied on the generated thumbnail.
 
 
Manipulated Instagram profile picture by name
 
 
The following PHP code creates the same URL:
<?php echo cl_image_tag("angelinajolieofficial.jpg",
             array("type": "instagram_name",
                   "width" => 90, "height" => 90, "crop" => "thumb", 
                   "gravity" => "face", "radius" => "max", "effect" => "improve")); ?>
Each Instagram profile has a unique numerical identifier in addition to the public user name. If you are using Instagram's APIs, you may prefer building the Cloudinary image delivery URLs based on Instagram's numeric IDs instead of user names.
 
The following examples fetch, manipulate, optimize and deliver the Instragram profile picture with the numeric ID 187971875. This time also adding a border to the image on the right.
 
 
Instagram profile picture by ID          Manipulated Instagram profile picture by ID
 
               
Below is a Javascript code for Node.js that generates the same circular thumbnail:
cloudinary.image("187971875.jpg", 
                 { type: 'instagram', width: 90, height: 90, crop: 'thumb', 
                   gravity: face, radius: 'max', 'effect': 'improve', 
                   border: '2px_solid_black'  });

Google+ profile pictures

The Google+ social network strives to be the ultimate Facebook alternative. Using Cloudinary, you can easily embed Google+ profile pictures in your website and mobile app. 
 
Do that by simply setting the image type to 'gplus' while building Cloudinary URLs. The images are identified by Google+ unique numeric ID.
 
The following URL delivers a 150x150 version of the Google+ profile of Larry Page that has the numeric ID of 106189723444098348646:
 
 
Google+ profile picture 
The following .Net code generates the same image:
cloudinary.Api.UrlImgUp.Action("gplus").Transform(
  new Transformation().Width(150).Height(150).Crop("scale")).
    BuildImageTag("106189723444098348646.jpg");
You can apply any Cloudinary image manipulation on the image. The following example generate a 150x150 face-detection based circular thumbnail while increasing the fill light of the resulting image and changing its colors to be more blueish.  
 
When generating rounded corners or circular images, you might want the background of the image to be transparent. This will allow you to place the image over a background image or pattern. To do that, just tell Cloudinary to convert the image format on-the-fly to the PNG format that supports transparent background (alpha channel).
 
 
Google+ manipulated profile picture as PNG         
 
The following Django code generates the same result:
cloudinary.CloudinaryImage("106189723444098348646.png").image(
             transformation = [
               { "width": 150, "height": 150, "crop": "fill", 
                  "gravity": "face", "radius": "max", "effect": "fill_light:30" },
               { "effect": "blue:50" }
             ]
            )
In addition to user profile pictures, Google+ (as well as Facebook) also maintains profile pictures of companies, products and figures. You can use the same 'gplus' image type to transform and deliver pictures of these additional Google+ pages as well. The following example delivers the picture of Google's Google+ page while scaling it to 100 pixels width, rotating by 30 degrees and applying a grayscale effect. This time, using the name of this page '+google'.
 
 
Google+ profile picture based on page name
 
 
While all code samples above rendered an HTML image tag on the server-side, you can use Cloudinary's jQuery plugin to dynamically embed social profile pictures from your client-side code on the browser side. Here's a jQuery example:
$.cloudinary.image("+google.jpg", 
  { transformation: { width: 100, crop: 'scale', effect: 'grayscale' }, angle: 30 })

Summary

Many of Cloudinary's customers already use Cloudinary to fetch, manipulate and deliver Facebook and Twitter profile pictures in their web and mobile sites and apps. Now you have the same simple integration available for both Google+ and Instagram. We hope you enjoy using these new features as well.
 
Profile picture delivery of all supported social networks is included in any of our plans. Try it out now.
blog comments powered by Disqus

Recent Blog Posts

How Answers.com manage millions of images

by Orly Bogler
How Answers.com utilizes Cloudinary to manage millions of images

When was the last time you've asked Google about your favorite band, movie star, or personal hobby? I can only assume that one of the first results that came up was from Answers.com. Nearly everyone knows this website, which is on the Quantcast Top 10 most visited sites in the world.

Read more
Control the zoom level with automatic image cropping

Many websites now offer their users the ability to upload images and profile pictures, making it a challenge for web designers to maintain a certain graphic design and style when subsequently displaying these images. The profile pictures may need to be smartly cropped to focus on the faces, with some sites that prefer close-ups of faces and others that prefer including more background when displaying images of people.

Read more
Introducing cloud based service for video management

They say that a picture is worth a thousand words. For modern websites, a video surely takes the visual impact to a whole new level.

Nowadays, people enjoy the amazing capability of shooting videos with smartphone cameras that easily fit in their back pockets and are accessible nearly everywhere. Modern web applications have an opportunity to dramatically increase their visual impact by showcasing these videos online. Between news reports, user shared video snippets, explainer videos and ad campaigns, we see more and more videos appearing daily in our visited websites.

Read more
Automatic and accurate red eye removal with Cloudinary

Red eye often happens due to the use of flash in low light conditions as the light hits the eye very quickly and into the retina. It then bounces off of the back of the eye and emits a red color due to the blood vessels there. Although more professional modern cameras and flashes generally prevent this from happening, red eye may still occur with simpler, smaller cameras (including smartphones). There are various software solutions for red eye removal available on mobile devices and desktops, some of which require manual processing to get good results.

Read more
How to detect and prevent malware infected user uploads

Social networking sites allow users to upload images or other types of files that are immediately available to other users via news feeds or notifications. In some cases, attackers can directly spread infected files, but more commonly, they leverage the viral effect and the fact that users are simply unaware that their files are infected through sharing and collaborating with others. As a site owner or application developer, it is your responsibility to protect users and prevent these situations from occurring. Fortunately, Cloudinary makes this easier with its Metascan add-on.

Read more