How to Resize Images in Power Automate
It’s easy enough to manually resize one or two images before using them somewhere (e.g., uploading them to a website) — but doing so at scale is a bit more of a challenge.
If we’re aiming to resize numerous images to a standard set of dimensions in a single workflow, we’ll want to create an automated workflow that consolidates our task into a single comprehensive action.
Thankfully, we can easily create that type of automated workflow in Power Automate. We can use the Cloudmersive Image Processing connector to set custom width and height dimensions for any images entering our flow, and we can immediately store our adjusted images in any folder we want.
Resize Images in Power Automate
We’ll walk through a quick example flow in this article that resizes several image files from a single folder in our system. In my example, all images will be JPEGs (sourced from a stock image service), but we’ll have no problem doing the same for PNG files as well.
As usual, we’ll build a manually triggered instant cloud flow in the context of our quick test-case.
We’ll begin by retrieving file bytes for each image in our target folder. If our images are stored in a SharePoint folder, we’ll use the List folder action, and if they’re stored in a OneDrive for Business folder, we’ll use the List files in folder action instead. My images are stored in the latter system, so I’ll be using that option in my example.
Next, we’ll add a Get file content action into our flow. This action will retrieve file bytes for each image file in our folder using the file identifier (Id) values obtained in our List files in folder action. Since the Id value is an array, Power Automate will automatically enclose our Get file content action in a For each control.
Now, within the For each control, we’ll add a new action and search for Cloudmersive connectors. To find the resizing action we’re looking for, we’ll want to navigate down to the Cloudmersive Image Processing connector with the yellow logo.
If the Resize an image action doesn’t show up immediately on the preview actions list as it did in my example, we’ll click “See more”, and we’ll then manually search (CTRL+F on our keyboard) the list for this action.
In the above screenshot, we’ll notice we also have the option to preserve the aspect ratio of our original images using a different version of the resizing action. We’ll ignore this option for now, and we’ll select the Resize an image action.
If it’s our first time using the Cloudmersive Image Processing connector (or any Cloudmersive connector for that matter), we’ll need to create our connection before we move forward and configure our request. To do that, we’ll need a free Cloudmersive API key, which we can get by visiting the Cloudmersive website and creating a free account. Free API keys give us a limit of 800 API calls per month on a regional Cloudmersive public cloud connection.
At this point, we’re ready to configure our image resizing request. All we need to do here is provide our desired width and height values in the Width and Height parameters respectively, and then provide our file bytes & file names (note — we don’t need our real file names for this to work correctly, but we can easily plug in the Display name value from our List files in folder step as I’ve done in my example). Dimensions are described in terms of pixels; in my example, I’ve chosen to resize each image in my initial folder to a Width and Height of 5000 x 5000.
As a quick note — any time we abandon our original aspect ratio, there’s a chance our images end up looking strange when the resizing operation is complete. This depends entirely on the original dimensions of the images we’re processing, so it’s important we choose new Width and Height dimensions that make sense for all our original files.
To wrap up our flow, we’ll now add a Create file action that generates the resized versions of our image files in the same folder they originally came from. We’ll use the Display name value once again to re-name our original images (in my example, I’ve added the word “Resized” before the Display name value to distinguish each image from the original), and we’ll use the Body value from our Resize an image step to get the new image contents.
We’ll now save and test our flow. Note that this flow might take a few minutes to run, depending on the file sizes of our original images and the traffic Power Automate & Cloudmersive servers are experiencing at any given time.
We’ll find our resized images alongside the originals in our target folder.
As we can see in my image previews, each resized image was converted to a square shape with 5000 x 5000 dimensions.
That’s all there is to it! We can now easily handle our image resizing workflows with a Power Automate flow.