How do I automate rescaling an image to fit in a square, leaving result square with transparency?

Discuss Pixelmator Pro tutorials and share useful resources.
User avatar

2020-06-29 14:15:54

I need to convert a large number of images to be 512x512. Each source image will be scaled proportionally to fit in 512x512, but I want the result to be 512x512 so I need to fill the unused space with transparent pixels. I don't see an obvious way to do that with the Automator actions provided. Can someone tell me what I have to do? While I'm a software engineer I find AppleScript totally inscrutable.
User avatar

2020-06-29 14:44:35

I found my answer using Pixelmator non-Pro actions. Posting it here for others to use.

1: Get Selected Finder Items
2: Copy Finder Items. To=my chosen output folder
3: Pixelmator: Change Type of Images. To Type=PNG.
4: Rename Finder Items: Make Sequential
5: Pixelmator: Fit Images. Width=512, Height=512, Scale proportionally=ON.
6: Pixelmator: Crop Images. Width=512, Height=512, Units=pixels, Anchor=center, Relative=OFF, Background Color=OFF.

The PNG conversion ensures the format supports transparency. The Crop step leaves the BG color off so transparency is used to fill to square.

I didn't see a Pro action for cropping, which is why I went with non-Pro for this workflow.
User avatar

2020-06-29 15:16:13

Yep, that should do it! And yes, there currently isn't a Crop Images action for Pixelmator Pro — we'll see what we can do about that.

P.S. This would also be possible using AppleScript, though it would take a little longer to write the script itself. I'm kind of intrigued by the challenge though, so I'll see if I can whip something up...
User avatar

2020-06-30 12:05:25

Alright, here's that script! First, a screenshot:
Image
And the downloadable script itself:

http://upload-cdn.pixelmator.com/ConvertTo512-10630.zip

Obviously, this took a lot longer than using Automator but it does come with some benefits – it's more customizable and more easily shareable, which is pretty cool. And, of course, it can be adapted to more complex workflows (or even used in Automator itself).

P.S. Our devs also found AppleScript to be quite a confusing thing at first but, as a non-programmer with a teeny bit of programming knowledge, I have to say I'm a little hooked on AppleScript.

P.P.S. I'm totally not an expert so certain things could probably be optimized (and I wrote out some extra code + used some extra variables to make the script easier to read) but, as far as I've tested, everything seems to work just fine!