URL2PNG Website Screenshots Add-on

Overview

Cloudinary is a cloud-based service that provides an end-to-end image management solution including uploads, storage, manipulations, optimizations and delivery.

Cloudinary offers a very rich set of image manipulation capabilities. Images can be uploaded to Cloudinary from your servers and directly from users' Web and mobile applications. In addition, Cloudinary can automatically fetch images from remote URLs and process images directly from Facebook, Twitter or Google+.

URL2PNG is a fast, reliable screenshots as a Service. Cloudinary provides an add-on for using URL2PNG screenshot creation capabilities, fully integrated into Cloudinary's image management and manipulation pipeline.

With URL2PNG's dynamic website screenshot creation, you can extend Cloudinary's existing set of image uploading sources. When using the URL2PNG add-on, Cloudinary's dynamic URLs can be used to generate screenshot images of public websites and further manipulate them to match your graphic design.

Using URL2PNG

Before you start, if you haven't done so already, please sign-up to a free Cloudinary account. After signing up, you can try the URL2PNG add-on for free and later on subscribe to a URL2PNG add-on plan that best matches your usage requirements.

To simplify the add-on integration, you can use Cloudinary's client libraries for: Ruby on Rails, Python & Django, PHP, Node.js, javascript, jQuery, Angular, Java, .NET, iOS, Android and Scala.

Generating a screenshot is performed on-the-fly using dynamic Cloudinary transformation URLs. The screenshot is created by the URL2PNG add-on and is then cached and delivered through a fast CDN. The following dynamic URL delivers a dynamically generated website screenshot:

Signed URLs

Cloudinary's dynamic image manipulation URLs are quite powerful and enable agile web and mobile development. However, due to the potential costs of users accessing unplanned dynamic URLs with URL2PNG screenshot directives, we request that you sign your image manipulation URLs or eagerly generate the requested screenshot using Cloudinary's authenticated API.

Note that once a certain version of a screenshot is generated using signed URLs or the authenticated API, all further image manipulations of the same image can be applied using unsigned dynamic Cloudinary URLs.

The following code example generates an image tag with a signed Cloudinary URL by setting the sign_url parameter to true. The image is resized to a 150x200 thumbnail using Cloudinary's fill crop mode applied with the north gravity.

Ruby:
cl_image_tag("http://cnn.com",
  :type => "url2png", 
  :crop => "fill", :width => 150, :height => 200, :gravity => :north, 
  :sign_url => true)
PHP:
<?php echo cl_image_tag("http://cnn.com", 
  array("type" => "url2png",
        "crop" => "fill", "width" => 150, "height" => 200, "gravity" => "north",
        "sign_url" => true)); ?>
Python:
cloudinary.CloudinaryImage("http://cnn.com", type = "url2png").image(
  crop = "fill", width = 150, height = 200, gravity = "north",
  sign_url = True)
Node.js:
cloudinary.image("http://cnn.com", 
  { type: "url2png",
    crop: "fill", width: 150, height: 200, gravity: north
    sign_url: true });
Java:
cloudinary.url().type("url2png").transformation(
  new Transformation().crop("fill").width(150).height(200).gravity("north")).
    signed(true).imageTag("http://cnn.com");

As you can see in the example below, the generated Cloudinary URL includes a signature component ('s--zoTi2OJH--'). Only URLs with a valid signature that matches the requested image manipulation will be approved for on-the-fly image manipulation and delivery.

For more details regarding signed URLs, see the following blog post: On-the-fly image manipulations secured with signed URLs.

Eager generation

As an alternative to signed URLs, you can eagerly generate and manipulate screenshots using Cloudinary's authenticated explicit API. This way you already use Cloudinary's authenticated API for requesting URL2PNG screenshot creation, therefore, accessing the generated images can be done using regular unsigned Cloudinary URLs.

Ruby:
Cloudinary::Uploader.explicit("http://en.wikipedia.org/wiki/Jpg", 
  :type => "url2png")
PHP:
\Cloudinary\Uploader::explicit(""http://en.wikipedia.org/wiki/Jpg", 
  array("type" => "url2png"));
Python:
cloudinary.uploader.explicit("http://en.wikipedia.org/wiki/Jpg", 
  type = "url2png")
Node.js:
cloudinary.uploader.explicit("http://en.wikipedia.org/wiki/Jpg", 
  function(result) { console.log(result) }, 
  { type: "url2png" });
Java:
cloudinary.uploader().explicit("http://en.wikipedia.org/wiki/Jpg", 
  ObjectUtils.asMap("type", "url2png"));

The authenticated API call above generates a screenshot of of a Wikipedia Web page. Now we can dynamically generate any derived image and thumbnail of the generated screenshot using unsigned Cloudinary delivery URLs. For example:

Create website screenshots

As shown in the examples above, a generated screenshot is a full size image. In order to embed a screenshot in your website or mobile application while matching your graphic design, you would need to generate a thumbnail of the original screenshot.

The following code snippet returns a URL for generating and delivering a 150x200 thumbnail of a screenshot generated by the URL2PNG add-on of a Wikipedia page.

Ruby:
cloudinary_url("http://en.wikipedia.org/wiki/Jpg",
  :type => "url2png", 
  :crop => "fill", :width => 150, :height => 200, :gravity => :north, 
  :sign_url => true)
PHP:
<?php echo cloudinary_url("http://en.wikipedia.org/wiki/Jpg", 
  array("type" => "url2png",
        "crop" => "fill", "width" => 150, "height" => 200, "gravity" => "north",
        "sign_url" => true)); ?>
Python:
cloudinary.CloudinaryImage("http://en.wikipedia.org/wiki/Jpg", type = "url2png").build_url(
  crop = "fill", width = 150, height = 200, gravity = "north",
  sign_url = True)
Node.js:
cloudinary.url("http://en.wikipedia.org/wiki/Jpg", 
  { type: "url2png",
    crop: "fill", width: 150, height: 200, gravity: "north"
    sign_url: true });
Java:
cloudinary.url().type("url2png").transformation(
  new Transformation().crop("fill").width(150).height(200).gravity("north")).
    signed(true).generate("http://en.wikipedia.org/wiki/Jpg");

The thumbnail is available using the following dynamic CDN URL:

Further image manipulations

Screenshot creation using the URL2PNG Cloudinary add-on can be mixed with any of Cloudinary's rich set of image manipulation capabilities.

For example, the following code first crops a screenshot to 400x200 while rounding its corners, adding a gray border and converting the image format to JPG. A light shadow is then added to the thumbnails, and finally, an uploaded image named url2png_logo is added as an overlay. The overlay image is rotated and colorized.

Ruby:
cl_image_tag("http://en.wikipedia.org/wiki/Jpg",
  :type => "url2png", 
  :transformation => [ 
    { :crop => "fill", :width => 400, :height => 400, :gravity => "north", 
      :radius => 50, :border => "2px_solid_rgb:999", :fetch_format => :jpg }, 
    { :effect => "shadow:20", :color => "#ccc" },  
    { :overlay => "url2png_logo", 
      :angle => 30, :effect => "colorize", :color => "#ec9800" }], 
  :sign_url => true)
PHP:
<?php echo cl_image_tag("http://en.wikipedia.org/wiki/Jpg", 
  array(
    "type" => "url2png",
    "transformation" => array( 
      array( "crop" => "fill", "width" => 400, "height" => 400, "gravity" => "north", 
        "radius" => 50, "border" => "2px_solid_rgb:999", "fetch_format" => "jpg" ), 
      array( "effect" => "shadow:20", "color" => "#ccc" ),  
      array( "overlay" => "url2png_logo", 
        "angle" => 30, "effect" => "colorize", "color" => "#ec9800" )), 
    "sign_url" => true)); ?>
Python:
cloudinary.CloudinaryImage("http://en.wikipedia.org/wiki/Jpg", type = "url2png").image(
 transformation = [ 
      { 'crop': "fill", 'width': 400, 'height': 400, 'gravity': "north", 
        'radius': 50, 'border': "2px_solid_rgb:999", 'fetch_format': "jpg" }, 
      { 'effect': "shadow:20", 'color': "#ccc" },  
      { 'overlay': "url2png_logo", 
        'angle': 30, 'effect': "colorize", 'color': "#ec9800" }],
   sign_url = True)
Node.js:
cloudinary.image("http://en.wikipedia.org/wiki/Jpg", 
  { type: "url2png", 
    transformation: [ 
      { crop: "fill", width: 400, height: 400, gravity: "north", 
        radius: 50, border: "2px_solid_rgb:999", fetch_format: "jpg" }, 
      { effect: "shadow:20", color: "#ccc" },  
      { overlay: "url2png_logo", 
        angle: 30, effect: "colorize", color: "#ec9800" }], 
    sign_url: true });
Java:
cloudinary.url().type("url2png").transformation(
   new Transformation().crop("fill").width(400).height(400).gravity("north").radius(50).           
    border("2px_solid_rgb:999").fetchFormat("jpg").chain().
      effect("shadow:20").color("#ccc").chain().overlay("url2png_logo").angle(30).
        effect("colorize").color("#ec9800")).signed(true).
          imageTag("http://en.wikipedia.org/wiki/Jpg");

The following dynamic manipulation URL generates and delivers the combined resized and overlayed screenshot:

For a full list of additional Cloudinary's image manipulation options, see Image transformations.