Cloudinary Blog

Beyond Drupal Media: Make Images and Video Fly with Cloudinary

 Beyond Drupal Media: Make Images and Video Fly with Cloudinary

Drupal is a very popular open source content management system (CMS) that has been deployed countless times by organizations and developers around the world. Drupal gained a reputation for being very flexible, powerful and robust in creating complex websites. With Drupal, you can create everything from plain websites, blogs and forums to ambitious enterprise systems.

In fact, a technical editor described Drupal this way: “Drupal knows exactly what it is and makes no excuses for: It strives to be a grenade launcher, not a Swiss army knife.” Some others likened Drupal to a powerhouse, not meant for mere mortals as compared to WordPress. Drupal is a registered trademark of Dries Buytaert, which founded Drupal and made the initial release public in 2001. Since then, Drupal has grown in leaps and bounds. The latest Drupal release is 8.3.5 at the time of writing.

Currently, Drupal powers about 7 percent of the total websites on the internet. As a developer setting up Drupal, one of the challenges you might face at some point is efficient handling of media assets (images and videos). Cloudinary is one of the amazing services out there with a clean API that can ease the pain of storing and transforming images in your Drupal-powered website.

Source: Appnovation, Expert Drupal Developers

Drupal and Cloudinary Integration

Fortunately for developers, Cloudinary offers a PHP SDK that can be integrated into any PHP-powered CMS.

  • Create an account on Cloudinary.
  • Install and enable the cloudinary PHP SDK in the libraries directory.
  • Set up your cloud name, API key and secret.

With the Cloudinary PHP SDK installed and enabled, there are a ton of transformations you can do to your images in your Drupal media library. Make sure the necessary Cloudinary files are present or required.

require 'Cloudinary.php';
require 'Uploader.php';
require 'Helpers.php';
require 'Api.php';

Let’s go through some image transformation techniques.

Resizing an uploaded image to half the original width while maintaining aspect ratio:

cl_image_tag("sample.jpg", array("width"=>0.5, "crop"=>"scale"))

Crop an image to a 400x400 circular thumbnail while automatically focusing on the face, and then scale down the result to a width of 200 pixels:

cl_image_tag("lady.jpg", array("transformation"=>array(
  array("width"=>400, "height"=>400, "gravity"=>"face", "radius"=>"max", "crop"=>"crop"),
  array("width"=>200, "crop"=>"scale")
  )))

Create a 150x150 thumbnail of an uploaded image with face detection:

cl_image_tag("woman.jpg", array("gravity"=>"face", "width"=>150, "height"=>150, "crop"=>"thumb"))

Generate a 100x100 face-detection-based circular thumbnail of an image named lady, and add another image named cloudinary_icon as a semi-transparent watermark with a width of 50 pixels:

cl_image_tag("lady.jpg", array("transformation"=>array(
  array("width"=>100, "height"=>100, "gravity"=>"face", "radius"=>"max", "crop"=>"thumb"),
  array("overlay"=>"cloudinary_icon", "effect"=>"brightness:200", "flags"=>"relative", "width"=>0.5, "opacity"=>60),
  array("dpr"=>2.0)
  )))

Decrease the size of the image by reducing the quality:

cl_image_tag("sample.jpg", array("quality"=>60))

No SDK? No Problem

While the PHP SDK is available, you might not be able to install or configure it as described above. Cloudinary provides on-the-fly URL transformation techniques that you can apply, enabling you to do exactly what is possible with the PHP SDK.

Let’s go through the image transformation techniques we performed above, but simply with the URL.

Resizing an uploaded image to half the original width while maintaining aspect ratio:

https://res.cloudinary.com/demo/image/upload/w_0.5/sample.jpg

Crop an image to a 400x400 circular thumbnail while automatically focusing on the face, and then scale down the result to a width of 200 pixels:

https://res.cloudinary.com/demo/image/upload/w_400,h_400,c_crop,g_face,r_max/w_200/lady.jpg

Create a 150x150 thumbnail of an uploaded image with face detection:

https://res.cloudinary.com/demo/image/upload/w_150,h_150,c_thumb,g_face/woman.jpg

Generate a 100x100 face-detection-based circular thumbnail of an image named lady, and add another image named cloudinary_icon as a semi-transparent watermark with a width of 50 pixels:

https://res.cloudinary.com/demo/image/upload/c_thumb,w_100,h_100,g_face,r_max/l_cloudinary_icon,e_brightness:200,fl_relative,w_0.5,o_60/dpr_2.0/lady.jpg

Decrease the size of the image by reducing the quality:

https://res.cloudinary.com/demo/image/upload/q_60/sample.jpg

Conclusion

We have learned a bit about how you can manipulate your images in Drupal using the powerful Cloudinary API. There are many more image optimization and transformation techniques you can perform via URL using Cloudinary.

With Cloudinary, you can store, and deliver media assets efficiently. Want more amazing image management solutions, check out the documentation.

Recent Blog Posts

How the Right Tools and Training Drive SDR Success

Here at Cloudinary, I head a team of eight SDRs, who are responsible for creating the first impression potential customers have of our company’s brand. In just the first 10 months of 2017, our team of outbound SDRs have been responsible for sending more than 67,000 personalized emails and making more than 15,000 calls.

Read more
The JS video player that developers will love (How To)

It doesn't take a genius (or a statistician) to know that video represents a significant proportion of web and mobile content these days. But did you realize that in 2017, video will account for about 75% of all internet traffic and that 55% of people watch videos online every day? In fact, 52% of marketing professionals worldwide believe that video is the content type with the best ROI, with people spending up to 2.6x more time on pages with video than on those without.

Read more
Curbing Terrorist Content Online

Today, Cloudinary is proud to announce that it has joined The Global Internet Forum to Counter Terrorism (GIFCT), to help fight the spread of terrorist and violent extremist content on the Internet. The forum was established by Facebook, Microsoft, Twitter and YouTube in mid-2017. Cloudinary will contribute to the hash-sharing database, which all contributing companies can use to help identify and block terrorist related images and videos upon upload.

Read more
Introducing the complete video solution for developers

Videos in web sites and apps are starting to catch up with images in terms of popularity and they are a constantly growing part of the media strategy for most organizations. This means bigger challenges for developers who need to handle these videos in their web sites and mobile apps. Cloudinary's mission is to solve all developer needs around image and video management. In this blog post, we are excited to introduce Cloudinary's complete cloud-based video management solution for developers.

Read more
Getting Started with StencilJS

Stencil is basically a compiler, not necessarily a UI library. A compiler that transforms TSX (TypeScript + JSX) into self-contained custom components.

Before you start learning about the tool, it’s important to note that Stencil is not another heavy JavaScript framework you need to learn. If you have worked with Angular or React, or understand web components, then Stencil is worth a look.

Read more