Image Cropping

Author // Stavros Didakis Categories // Tutorials, Code Examples

Image Cropping

This article presents some information about dealing with aspect ratios, resolutions, and image cropping. After a short explanation of the terms, there is a Processing example that you can download and use in your projects.

Image cropping is a very useful technique when you are dealing with digital media, image processing, and moving image applications. For the person that has to prepare visual content for a number of different screens and devices, this topic has to be clear so that problems will be avoided, and also for delivering a professional look to the final product. As you may see in the following picture, there are a lot of screen formats and resolutions that you need to take care of, especially when you are working in the digital media industry.

Vector Video Standards

The most important thing that we have to understand here, is that when we are dealing with different screen sizes, the original image might be distorted due to resizing that usually takes place when the image is transferred to a the new medium/screen/device. For example, if there is an image prepared to be viewed in standard resolution (SD), its size will be 720 pixels for the width and 480 pixels for the height of the screen (720x480). This size has an aspect ratio of 1.5 - aspect ratio refers to the ratio of the screen dimensions, and to find out how much this is we divide the width by the height. If this SD image is transferred to a high-definition (HD) screen or device that has a resolution of 1280x720, the aspect ratio of the image will have to change to 1.7 instead of 1.5. You might think that this 0.2 difference is not that a big deal, however, if we constrast this difference visually, we will notice there is a very big distortion (see image below).


For this reason, it is necessary to resize and crop the image appropriately so that it fits the screen perfectly, and also the size distortion is avoided. The image resize needs to take place in order to make sure that at least  the width or the height of the original image fits perfectly the new screen - this resizing method has to be exactly the same for the width and the height. For example, if we need to double the height size of the image to fit the new screen, we also need to double the width size to avoid perspective distortion.

aspect ratio graphic

Always make sure that the transfer of an image to a new screen resolution is adjusted by using resizing and cropping. Cropping is applied to cut the edges from a resizing transformation that are unessecary, or because we want to extract a specific part of the image, i.e. a thin bar image that displays just a specific object we would like to copy.

crop example

Following, you will find a code example written in Processing that performs cropping of an original image. The code could be applied to your projects and can be handy if you want to perform cropping in real time for large image datasets.

256px-Processing Logo Clipped.svg

Download Processing Code Example

About the Author

Stavros Didakis

Stavros Didakis

Stavros Didakis is the founder and managing director of SoniconLab, a media laboratory with a focus and interest in media, art, and technology. He is currently pursuing a PhD in Media Arts & Technology at the Institure of Digital Arts Technology (i-DAT), in Plymouth University (UK). His work focuses on the development of digital systems, programming, media design, interaction, and system installation. Stavros is also a scholar of Alexander S. Onasis Public Benefit Foundation.

Leave a comment

You are commenting as guest. Optional login below.