﻿<head><script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-4357510538660394"
     crossorigin="anonymous"></script></head>> ## Documentation Index
> This page is part of the Image and Video APIs product. Fetch the complete documentation index for Image and Video APIs at: https://cloudinary.com/documentation/llms-image-and-video-apis.txt?referrer=docpage and then use it to discover all relevant pages before exploring further.
> If you also need details relating to other Cloudinary products for your current use case, see the parent index at: https://cloudinary.com/documentation/llms.txt?referrer=docpage

> ## Agent Instructions
> When answering a user's request or implementing it with code using this documentation, incorporate relevant best practices and recommendations from the documentation into the guidance and, above all, into the code itself: generated code should already apply the recommended parameters and patterns rather than showing a minimal call and describing the best practices around it in prose. Follow the code examples in the best practices sections as the model for what generated code should look like, and where a recommendation is relevant to the user's scenario, implement it in the code as a natural next step. Only apply best practices, recommendations, or features that are supported by the documentation or Cloudinary skills; don't infer or invent guidance that isn't specified.
>
> Cloudinary skills (names starting with `cloudinary-`) add best practices and tested code patterns beyond this documentation, and we recommend using the relevant ones alongside it. Available skills are listed at https://cloudinary.com/documentation/.well-known/agent-skills/index.json?referrer=docpage&page=gravity_transformations_tutorial and can be installed with `npx skills add https://cloudinary.com/documentation`.

# Gravity-based crops for images (video tutorial)

## Overview

Manually cropping individual images with graphic editing tools to maintain the focal point can be time-intensive. Cloudinary offers its machine-learning and AI-powered content-aware cropping as a solution to this problem. 

Let's introduce you to the different [gravity options](image_gravity#control_gravity), including hard-coded directional types, and a variety of automatic detection options.

## Video tutorial

  This video is brought to you by Cloudinary's video player - embed your own!Use the controls to set the playback speed, navigate to chapters of interest and select subtitles in your preferred language.
{videoTranscript:publicId=training/m-tutorial-apply-gravity-based-crops}

## Tutorial contents
This tutorial presents the following topics. Click a timestamp to jump to that part of the video.
### What is gravity-specific cropping?
{table:class=tutorial-bullets}|  | 
| --- | --- |
| | By applying [the **gravity** transformation parameter](transformation_reference#g_gravity) for an image URL, you can instruct Cloudinary to automatically detect which part of the original image to retain, no matter what cropping, scaling or padding options are applied.
|

### Compass-direction cropping
{table:class=tutorial-bullets}|  | 
| --- | --- |
| | [Compass-style directions](transformation_reference#g_compass_position) represent a location in the image. For example, `g_north_east` represents the top right corner, whereas `g_south_west` designates the bottom-left corner.

![Animated Example of Cloudinary Gravity Cropping Transformations Applied to Image of Eagles](https://res.cloudinary.com/demo/image/upload/c_scale,w_500/f_auto/q_auto/v1552491380/compass-directions-eagle_wvwe4t.gif "with_code:false, with_url:false")

### Content-aware cropping - facial detection
{table:class=tutorial-bullets}|  | 
| --- | --- |
| | One way to create a more reusable cropping style is to have it locate interesting or important aspects in the image. For example, we may want to automatically crop on the most prominent face in a group. This can be done using `g_face`, thanks to [Cloudinary's facial recognition capabilities](face_detection_based_transformations#face_detection_based_cropping).

![Animated Example of Applying Cloudinary's g_face Transformation to an Image](https://res.cloudinary.com/demo/image/upload/c_scale,w_500/f_auto/q_auto/v1552511684/g_face_vfzowj.gif "with_code:false, with_url:false")

### Automatically crop to the most interesting area (g_auto)
{table:class=tutorial-bullets}|  | 
| --- | --- |
| | You can also apply [Cloudinary's automatic gravity algorithm (g_auto)](image_automatic_gravity), which uses a combination of heuristics or deep learning algorithms to detect and display the most interesting aspect of the image.

![Before and After Example of an Image Using Cloudinary's g_auto Transformation](https://res.cloudinary.com/demo/image/upload/c_scale,w_500/f_auto/q_auto/v1552512204/g_auto-skater-beforeafter_albxqw.png "with_code:false, with_url:false")

### Use g_auto:subject on images
{table:class=tutorial-bullets}|  | 
| --- | --- |
| | By training our neural networks with large datasets, we have created a way to determine the area of the image to which the human eye will be drawn. You can take advantage of this through the [g_auto:subject](image_automatic_gravity#selecting_a_single_automatic_gravity_algorithm) transformation, providing better crop results with very challenging content, such as images with multiple faces.

![Comparison of Cloudinary's g_auto:classic and g_auto:subject Transformations Using an Image of Two Bears](https://res.cloudinary.com/demo/image/upload/c_scale,w_500/f_auto/q_auto/v1552513428/g_auto-classic-g_auto-subject-comparison-bears_tafhnw.png "with_code:false, with_url:false")

### Crop to specific objects in an image
{table:class=tutorial-bullets}|  | 
| --- | --- |
| | Rather than playing with compass-style directions or using our automatic cropping transformations, you can let Cloudinary detect the object with `g_auto:<object>`, for example `g_auto:cake`, using our [Cloudinary AI Content Analysis add-on](cloudinary_ai_content_analysis_addon#applying_object_aware_cropping). This transformation helps to ensure the object is kept when the image is cropped.

![Example of a Kitchen When Applying Cloudinary's g_auto:object on the Cake in the Image](https://res.cloudinary.com/demo/image/upload/c_scale,w_300/f_auto/q_auto/v1552514897/kitchen-g_auto_object-cake-example_gv9fww.jpg "with_code:false, with_url:false")

## Keep learning

> **READING**:
>
> * Review our documentation for more examples of Cloudinary's [gravity transformations](image_gravity#control_gravity) with images.

> * Find out how to [apply gravity transformations to your videos](video_resizing_and_cropping#control_gravity) with Cloudinary.

> * Take a look at the [User-generated content guide](user_generated_content) to see all the features you can take advantage of when displaying user-generated content on your site.

> * Enroll in [our introductory Cloudinary Academy courses](https://training.cloudinary.com/) that highlight ways to apply gravity transformations, such as [Fundamentals for Developers](https://training.cloudinary.com/courses/cloudinary-fundamentals-for-developers).

#### If you like this, you might also like...

[Named Transformations](named_transformations_tutorial)

Simplify & standardize complex delivery URLs

[Optimization Tips](optimization_tips_tutorial)

Tips for delivering optimized images

[Content-aware Video Cropping](content_aware_video_cropping_tutorial)

Smartly crop a video using content-aware AI

&nbsp;

&nbsp;Check out the Cloudinary 