Help with workflow to automatically auto-crop (or ML crop) a batch of similar files.

Talk about Pixelmator Pro, share tips & tricks, tutorials, and other resources.
User avatar

2021-07-06 04:01:37

Hoping someone can help or offer advice. I take a large number of photos of DVD / Blu Ray movies for listing on an ecommerce site. The items are all similar size & shape (rectangle) photographed using a copy stand from above on a white background. The white background doesn't come into the images as a perfectly solid white - at a pixel level its a mottled variety of gray shades.

I'm trying to create the following workflow / quick action.

Open image
Crop white area
export image as a jpg to a new folder
repeat with next image

I tried using the pixelmator "trim images" command in automator, but the background white isn't a solid colour so selecting the top left or bottom right pixel colour doesn't work.

If I can't get a crop tight to the outside of the image, I've found that the new ML crop produces a usable image however I can't see how to access this feature via Automator.

Happy to post online or send some sample images if that helps get an answer.

Thank you in advance!
User avatar

2021-07-08 12:42:29

ML Crop is not scriptable or available as an Automator action for now but I've pinged the team about it. We'll see what we can do. I the meantime, you could try automating this process using AppleScript. For instance, try running the following script in Script Editor and see if it works with your images:
tell application "Pixelmator Pro"
	activate
	tell the front document
		select color range color {65535, 65535, 65535} range 10
		clear
		deselect
		trim canvas mode transparency
	end tell
end tell
This script uses the Select Color Range feature to select the white areas in your image (you can adjust the selection range, if needed), then clears the selection and trims the transparent pixels. This method is not universal and might not work if there are a lot of while areas in the image itself but it might just be worth giving a try.
User avatar

2021-07-08 15:08:55

Instead of clear is there a command to set the color 'white'? That could retain white in the image?
User avatar

2021-07-08 16:04:27

Sure! You'll just need to replace a couple of lines:
tell application "Pixelmator Pro"
	activate
	tell the front document
		select color range color {65535, 65535, 65535} range 10
		fill the first layer with color {65535, 65535, 65535}
		deselect
		trim canvas mode top left color
	end tell
end tell
Although if the white in the image wasn't exactly white originally, it may look a bit odd.