How to Maintain Aspect Ratio When Resizing Images in Power Automate

Cloudmersive
4 min readDec 3, 2024

--

Aspect ratio defines the relative width and height of an image. Maintaining this ratio is important for preserving the aesthetic and quality of an image during an image resizing workflow.

We can, of course, choose to resize images without respect to aspect ratio if we want to — and that’s fine, as long as we carefully pick width and height values that don’t overly distort the image quality. We walked through the process of resizing images in Power Automate in another article.

In this article, we’ll run through an example Power Automate flow that resizes an image from our file system while maintaining the original aspect ratio as a top priority. Instead of defining entirely new width and height values in our image resizing request, we’ll define maximum values for each.

We’ll build a manually triggered, instant cloud flow in this context so we can easily control our inputs when we run our image resizing test.

In the first step of our example flow, we’ll use a Get file content action to retrieve an image file from our system.

The image resizing action we’ll eventually use can work with PNG or JPG images, so we’ll want to ensure our image matches one of those formats.

In our second step, we’ll add a new action and type “Cloudmersive” into the connector search bar. This brings up a list of all the Cloudmersive connectors available in the Power Automate connector library.

We’ll locate the Cloudmersive Image Processing connector on this list (it has a yellow logo) and click “See more” to view its full list of actions.

From here, we’ll CTRL+F search for an action called Resize an image while preserving aspect ratio, and we’ll select it once we find it.

Assuming we haven’t used the Cloudmersive Image Processing connector before, we’ll need to create and authorize our connection before we can utilize this action in our flow.

We can create our connection for free with a free Cloudmersive API key. To get a free API key, we’ll simply need to create a free account on the Cloudmersive website. Free API keys allow up to 800 API calls per month with zero commitments; they’re intended for small-scale production needs and testing.

After we’ve successfully authorized our connection, we’ll begin filling out four request parameters. These parameters as for a maximum output image width, a maximum output image height, a set of file bytes (i.e., our image file), and a file name (any name we want — this doesn’t have to be the real name of our original image as shown in our file system).

As we can see in the above screenshot, I’ve structured a request that will resize my input image to a maximum width and height of 1000 pixels. In order to understand the way these values will be interpreted; we need to understand the original aspect ratio of our image.

My example image (a generic stock photo) below has a width of 6720 and a height of 4480, which comes out to an aspect ratio of 3:2.

As such, when I resize the maximum width of my image to 1000, the height will come as close to 1000 as possible without overriding the aspect ratio. This means I’ll end up with a height around 666 pixels.

To see this in action, we’ll add a Create file action to our flow and write the result of our image resizing action to a new .jpeg file in our system.

Now we’ll save and test our flow.

When our flow finishes running, we’ll find our resized file, open it, and compare it to the original file.

In the above example, we can see my resized photo (left) and my original photo (right). The resized image has a height of 666 pixels as expected, with a height of 1000 pixels.

Using this image resizing action in our flow, we can easily images to new aspect ratios without needing to worry about distorting the structure and aesthetic of the original file.

--

--

Cloudmersive
Cloudmersive

Written by Cloudmersive

There’s an API for that. Cloudmersive is a leader in Highly Scalable Cloud APIs.

No responses yet