How Smart Crop can help you deliver perfect responsive images on each device
Tags: imageoptimization, javascript, webdev, webperf
Published: 2019-01-17 08:40:07

---
title: How Smart Crop can help you deliver perfect responsive images on each device
published: true
description: Perfect delivery of Images on each device using smartcrop
tags: #imageoptimization #javascript #webdev #webperf
canonical_url: https://imagekit.io/blog/smart-crop-deliver-perfect-responsive-images/
cover_image: https://thepracticaldev.s3.amazonaws.com/i/718sa7sswdm0m7u8dy8k.png
---

Images are a critical piece of all websites and apps. Whether it is an e-commerce store, a travel website or a content website, a typical website would have hundreds of thousands of images. The number can be significantly higher if you have user-generated content on the website. With such a large number of images on a website, for a [perfect responsive image experience](http://imagekit.io/blog/how-to-deliver-responsive-images-across-multiple-devices/) on each user’s device, the images should also change according to the device that is requesting them. Which means that instead of resizing the image using CSS, the image that loads on a mobile device should be actually smaller in dimensions than the one that loads on a desktop device.

## Why does regular cropping fail?

In such a scenario, where a variety of images have to be resized for different devices and different placeholders, cropping in an image is inevitable. And the default cropping strategy adopted for images is centre cropping – preserve the centre of the image and crop out from the edges. While this strategy works fine for a lot of cases, it can fail when the subject is not at the centre of the image. Here are some examples of poor thumbnails as a result of centre cropping –

| Original Images (scaled down) | Image thumbnails 150px x 200px |
| --- | --- |
| ![](https://ik.imagekit.io/demo/img/smart_crop_blog/test_image_1_BJ6GYWWbN.jpeg?tr=w-400) | ![](https://ik.imagekit.io/demo/img/smart_crop_blog/test_image_1_BJ6GYWWbN.jpeg?tr=w-150,h-200) |
| ![](https://ik.imagekit.io/demo/img/smart_crop_blog/test_image_2_r1QOFZ-bE.jpeg?tr=w-400) | ![](https://ik.imagekit.io/demo/img/smart_crop_blog/test_image_2_r1QOFZ-bE.jpeg?tr=w-150,h-200) |
| ![](https://ik.imagekit.io/demo/img/smart_crop_blog/test_image_3_H1LQ5Wb-E.jpeg?tr=w-400) | ![](https://ik.imagekit.io/demo/img/smart_crop_blog/test_image_3_H1LQ5Wb-E.jpeg?tr=w-150,h-200) |
| ![](https://ik.imagekit.io/demo/img/smart_crop_blog/test_image_4_ryB8GMWbE.jpeg?tr=w-400) | ![](https://ik.imagekit.io/demo/img/smart_crop_blog/test_image_4_ryB8GMWbE.jpeg?tr=w-150,h-200) |

*You may get away with such thumbnails on your website, not all of your users may care about it. But if you are one of those companies, that want to deliver a perfect experience to your users, even if it is a thumbnail of a product, you would not want such improperly cropped thumbnails to be shown to your users.*
 

**What’s the solution then? How do we ensure that we are cropping the images correctly while creating thumbnails?**

## Enter ImageKit’s Smart Crop

Smart Crop is a content-aware cropping method available to all ImageKit users that analyses the image content and tries to ensure that the most important part of the image is always at the centre of the final thumbnail.

Let’s see how it works for the images where the centre crop failed.

| Original Images (scaled down) | Centre-cropped image thumbnails 150px x 200px | Smart-cropped image thumbnails 150px x 200px |
| --- | --- | --- |
| ![](https://ik.imagekit.io/demo/img/smart_crop_blog/test_image_1_BJ6GYWWbN.jpeg?tr=w-400) | ![](https://ik.imagekit.io/demo/img/smart_crop_blog/test_image_1_BJ6GYWWbN.jpeg?tr=w-150,h-200) | ![](https://ik.imagekit.io/demo/img/smart_crop_blog/test_image_1_BJ6GYWWbN.jpeg?tr=w-150,h-200,fo-auto) |
| ![](https://ik.imagekit.io/demo/img/smart_crop_blog/test_image_2_r1QOFZ-bE.jpeg?tr=w-400) | ![](https://ik.imagekit.io/demo/img/smart_crop_blog/test_image_2_r1QOFZ-bE.jpeg?tr=w-150,h-200) | ![](https://ik.imagekit.io/demo/img/smart_crop_blog/test_image_2_r1QOFZ-bE.jpeg?tr=w-150,h-200,fo-auto) |
| ![](https://ik.imagekit.io/demo/img/smart_crop_blog/test_image_3_H1LQ5Wb-E.jpeg?tr=w-400) | ![](https://ik.imagekit.io/demo/img/smart_crop_blog/test_image_3_H1LQ5Wb-E.jpeg?tr=w-150,h-200) | ![](https://ik.imagekit.io/demo/img/smart_crop_blog/test_image_3_H1LQ5Wb-E.jpeg?tr=w-150,h-200,fo-auto) |
| ![](https://ik.imagekit.io/demo/img/smart_crop_blog/test_image_4_ryB8GMWbE.jpeg?tr=w-400) | ![](https://ik.imagekit.io/demo/img/smart_crop_blog/test_image_4_ryB8GMWbE.jpeg?tr=w-150,h-200) | ![](https://ik.imagekit.io/demo/img/smart_crop_blog/test_image_4_ryB8GMWbE.jpeg?tr=w-150,h-200,fo-auto) |

 

**In each case, the smart crop was able to get the most important part of the image in the centre.**

## How to enable smart crop in the image URL?

Well, it’s really simple. Along with the height and width, you need to specify the `focus` mode for cropping and set it to `auto`. This is done using the `fo-auto` parameter in the transformation string in the URL. For example,

```
https://ik.imagekit.io/demo/img/tr:w-150,h-200,fo-auto/test_image.jpg
```
  
You can [read more about this focus parameter in ImageKit here](https://help.imagekit.io/start-delivering-resized-and-optimized-images/resize-crop-and-responsive-images/crop-crop-modes-and-focus).
## Practical applications of smart crop

Now that we have seen how ImageKit works, let’s take a look at how you can use it on your website.

**1. For e-commerce websites**  
*Creating perfect product thumbnails*

A product needs to be displayed on multiple pages on your website or app – the listing page, the product detail page, as a small thumbnail in an image carousel etc. With smart crop, you can ensure that each product thumbnail is perfect and showcases your product the way it should be done.

Here is how it smart crop can help your e-commerce store. We are using scaled-down versions of images here for display, but it does give an idea about the power of smart crop.

| Original Image |
| --- |
| ![](https://ik.imagekit.io/demo/img/smart_crop_blog/test_image_5_ByBvwmbWV.jpeg?tr=w-500) |

| **Without Smart Crop** |
| --- |

| **Mobile Thumbnail**  200px x 200px | **Desktop Listing Page**  350px x 300px | **Desktop Product Carousel**  400px x 600px (scaled to 60%) |
| --- | --- | --- |
| ![](https://ik.imagekit.io/demo/img/smart_crop_blog/test_image_5_ByBvwmbWV.jpeg?tr=w-200,h-200) | ![](https://ik.imagekit.io/demo/img/smart_crop_blog/test_image_5_ByBvwmbWV.jpeg?tr=w-350,h-300) | ![](https://ik.imagekit.io/demo/img/smart_crop_blog/test_image_5_ByBvwmbWV.jpeg?tr=w-400,h-600) |

| **With Smart Crop** |
| --- |

| **Mobile Thumbnail** 200px x 200px | **Desktop Listing Page** 350px x 300px | **Desktop Product Carousel** 400px x 600px (scaled to 60%) |
| --- | --- | --- |
| ![](https://ik.imagekit.io/demo/img/smart_crop_blog/test_image_5_ByBvwmbWV.jpeg?tr=w-200,h-200,fo-auto) | ![](https://ik.imagekit.io/demo/img/smart_crop_blog/test_image_5_ByBvwmbWV.jpeg?tr=w-350,h-300,fo-auto) | ![](https://ik.imagekit.io/demo/img/smart_crop_blog/test_image_5_ByBvwmbWV.jpeg?tr=w-400,h-600,fo-auto) |


**2. Travel & content websites and user-generated images**  
*Get the most important region in your thumbnails*

ImageKit’s smart crop can automatically determine the most important part in an image, whether it’s a monument or a landscape or a car, and preserve it in the final thumbnail.

Here are a few examples of the smart crop in action for different kinds of images –

| Original Image | 
| --- |

| ![](https://thepracticaldev.s3.amazonaws.com/i/ikri6hrz7q0a7toxc5p0.png) | ![](https://thepracticaldev.s3.amazonaws.com/i/gkkgycnf6k3bmaa80vzj.png) 
| --- | --- |

| **Without Smart Crop** |
| --- |

| **Mobile Thumbnail**  200px x 200px | **Desktop Cover Image**  800px x 300px (scaled to 60%) |
| --- | --- |
| ![](https://thepracticaldev.s3.amazonaws.com/i/c7580hxkv4mokzfy0yic.png) | ![] (https://thepracticaldev.s3.amazonaws.com/i/yn31s5rtn8zwome6f8kw.png) |

| **With Smart Crop** |
| --- |

| **Mobile Thumbnail**  200px x 200px | **Desktop Cover Image**  800px x 300px (scaled to 60%) |
| --- | --- |
| ![](https://thepracticaldev.s3.amazonaws.com/i/rq4vuly2cjdzx5uezfk3.png) | ![](https://thepracticaldev.s3.amazonaws.com/i/ercirw09amlszctjbl5b.png) |

 
## Face thumbnails with smart crop

Till now, we have seen how smart crop works great for bringing the subject to the centre of the image. But there is more to it.

The smart crop has another **face-cropping mode** that finds out the face from an image and extracts it to create a thumbnail. This would help in cases where you need to create profile pictures from a user’s photo.

Here are a few examples of the face-cropping mode in action

| Original Image | Regular Smart Cropped Image | Face-cropped Image |
| --- | --- | --- |
| ![](https://ik.imagekit.io/demo/img/smart_crop_blog/test_image_8_rkOgXV-W4.jpeg?tr=w-500) | ![](https://ik.imagekit.io/demo/img/smart_crop_blog/test_image_8_rkOgXV-W4.jpeg?tr=w-200,h-200,fo-auto) | ![](https://ik.imagekit.io/demo/img/smart_crop_blog/test_image_8_rkOgXV-W4.jpeg?tr=w-200,h-200,fo-face) |
| ![](https://ik.imagekit.io/demo/img/smart_crop_blog/test_image_9_By_lQN-WE.jpeg?tr=w-500) | ![](https://ik.imagekit.io/demo/img/smart_crop_blog/test_image_9_By_lQN-WE.jpeg?tr=w-200,h-200,fo-auto) | ![](https://ik.imagekit.io/demo/img/smart_crop_blog/test_image_9_By_lQN-WE.jpeg?tr=w-200,h-200,fo-face) |
| ![](https://ik.imagekit.io/demo/img/smart_crop_blog/test_image_10_ryQQVNZWV.jpeg?tr=w-500) | ![](https://ik.imagekit.io/demo/img/smart_crop_blog/test_image_10_ryQQVNZWV.jpeg?tr=w-200,h-200,fo-auto) | ![](https://ik.imagekit.io/demo/img/smart_crop_blog/test_image_10_ryQQVNZWV.jpeg?tr=w-200,h-200,fo-face) |

## How to get the face cropping mode for your images?

Again, like every other transformation in ImageKit, this one is really simple as well. You need to set the value of the `focus` parameter to `face` in your image URL. This is done using the `fo-face` parameter in the transformation string in the URL. For example

```
https://ik.imagekit.io/demo/img/tr:w-200,h-200,fo-face/test_image.jpg
```

## Putting it all together with other transforms

Apart from the examples demonstrated above, you can combine smart cropping with other transforms in ImageKit to create really cool user interfaces.

Let’s say, just like Facebook, you want to create a user’s profile page with a user profile picture and a cover photo. Let’s take these two images for the same.

| ![](https://ik.imagekit.io/demo/img/smart_crop_blog/test_image_9_By_lQN-WE.jpeg?tr=w-500) | ![](https://ik.imagekit.io/demo/img/smart_crop_blog/test_image_7_Hyi1-V-b4.jpeg?tr=w-500) |
| --- | --- |

With the smart crop set to face-crop mode and the radius transformation, we can get a rounded profile picture of the user.  
 ![](https://ik.imagekit.io/demo/img/smart_crop_blog/test_image_9_By_lQN-WE.jpeg?tr=w-200,h-200,fo-face:r-max)

We can then use the regular smart crop and blur transformation to resize the cover photo as per the required size for desktop and mobile devices.  
 ![](https://ik.imagekit.io/demo/img/smart_crop_blog/test_image_7_Hyi1-V-b4.jpeg?tr=w-400,h-150,fo-auto,bl-5)

Combining these two pictures using HTML and CSS (or in an app), this is how the end result can look like on different devices

| ![](https://ik.imagekit.io/demo/img/smart_crop_blog/sample2_B1vhuVZ-4.png?tr=w-500,f-png) | ![](https://ik.imagekit.io/demo/img/smart_crop_blog/sample1_HJDhu4bWN.png?tr=w-500,f-png) |
| --- | --- |

## Conclusion

Using smart crop for your images requires a very small change in your image URLs but it can help you inch closer towards a perfect image experience across devices. Just add fo-auto for general smart crop and fo-face for the face-crop mode of smart crop. It is especially useful if you get a lot of user-generated content or the main subject in the photos is off-centre.

So, what are you waiting for? Give it a try for your images and start delivering a better experience to your users.