Trimming (auto-cropping) selected images

Hi, I needed a button to trim (auto-crop) a selected image. So I created this one:

"C:\Program Files\ImageMagick-6.6.5-Q16\convert.exe" "{filepath}" -trim +repage "{sourcepath}{file|noext} - trimmed{file|ext}"

(You may need to edit the path to convert.exe for your version of ImageMagick.)

Explanation: Using ImageMagick - the versatile and free graphic utility - the button auto-crops the selected image(s), adds the suffix " - trimmed" to each one, and saves the new images in the source folder.

Auto-crop means that ImageMagick looks at the edges of the image and automatically works out if there is a border and what color it is, then removes it. It removes "unnecessary mono-color pixel areas" from the edges of a picture by reducing the canvas size of the image.

1 Like

I installed ImageShack and your button last night and it seems to work well ... with one exception. The test images that I used had fairly large white borders around the images. The crop command reduced this white border by about half or two-thirds but didn't eliminate it completely. I looked at the ImageShack documentation (well, briefly) and couldn't figure out a way to expand how much of the border was removed. Do you have any experience using ImageShack to do this?

Maybe the "fairly large white borders around the images" was not of the exactly same color value, although it could appear so to your eyes.

I don't think that's the problem. I'm using a graphic app that starts with a blank white page onto which I'm adding a frame and then graphic elements inside the frame. I was trying to use ImageShack to then eliminate the white border around the frame. Is there an easy way to check to see if all of those pixels are the same? And note that ImageShack did crop most of the white border, just not all of it.

AFAIR there is a parameter which controls this kind of offset. You have to read the ImageMagick documentation. Or maybe you have an other ImageMagick version. I use this command:

"C:\Program Files\ImageMagick-6.6.5-Q16\convert.exe" {filepath} -trim +repage "{sourcepath}{file|noext} - trimmed{file|ext}"

I'll give that a try. Thanks.

Oh, and what did you mean about an other ImageMagick version? Are you talking just about v6.6.5 etc. or is there a wholly different edition of the program available? I just downloaded it a few weeks ago.

awesome button! exactly what i needed! cheers!!!! :slight_smile: :slight_smile:

I am glad you like it!

I wonder is there a function to analyze the best crop dimension across an animation [sequence of images] ie. so the image dimension of the crop is be best average of all the images in the sequence. It would save loading in say After Effects, looking at the sequence and cropping and re-rendering...

Do you mean analyze which animation frame (PNG images in some folder) is the largest after being cropped (by alpha), and then crop all of them to that common size? I've made such utility for work some time ago, if you need it, I can make you a simplified stripped-down version.

Hey thanks a mil - what are the requirements for it to work ... FFmpeg/ImageMagick?
Sorry didn't see post, must check how to get emails...

[quote="AlanEd"]Hey thanks a mil - what are the requirements for it to work ... FFmpeg/ImageMagick?
Sorry didn't see post, must check how to get emails...[/quote]
There are no separate requirements*, it's an already-compiled C++ utility (uses FreeImage library). Check the attached cropAnimFrames.7z below which contains the utility executable and the accompanying FreeImage dll.

While it supports command-line parameters (run it with -? in the console to get the list) you can also just double-click it from Opus (or Explorer) and it will ask you for the path so you can paste a folder path which contains your PNG frames and it will process them as described in my previous comment. Directory "autocropped" will be automatically created and processed versions of your frames will be there.

* depending on your OS, you may need Visual C++ Redistributable for Visual Studio 2015 if it fails to execute.

I hope it will work for you :slight_smile:
cropAnimFrames.7z (1.37 MB)

Many thanks for that will try it out, will save a few minutes going in and out of After Effects...

Hello @bytespiller
*I know this thread is years old but I'll ask the question, in case there was an update to that utility.
This was working great but I think since I have set up my OneDrive, that it's not dealing well with an unusual character in the file path.
Works fine on say :
Doesn't work:
D:\OneDrive - VTEÉ\Old

Thank you,

Also some useful information that you can do this from imagemagick (I think*), here is the relevant thread, but I haven't pieced it together yet.

The utility itself was never updated, but I do have the source code so I'll see what I can do to modernize it (unicode paths & spaces, 64 bit etc.).

1 Like

Here is the updated version (64 bit), it now supports unicode paths and spaces, but with some caveats:

  1. If running this utility in the interactive mode (just double-clicking it) the unicode path input may not work due to way Windows CMD works. However, you can use the command line -i "some/path" switch, that should work (you're probably already using it that way).
  2. It's best to enclose the paths in quotes, this way spaces are supported. Paths can be relative or absolute.
  3. Both the forward slashes / and the backslashes \ are supported in directory paths, however the backslashes must be escaped like so: \\ (at least in the CMD).

cropAnimFrames_v0.2.7z (1.9 MB)

Wonderful! that is working perfectly.
Here is my button command. I have the utility in my user folder for Opus, so it comes with me and also is captured in Opus backups. Really appreciate that. Nearly* got other methods to work! So kind to sort that out.

/profile\AppData\Roaming\GPSoftware\Directory Opus\User Data\CROP\cropAnimFrames.exe  -i {sourcepath$|noterm}

I would add quotes around the exe path, so it doesn't stop working if something creates folders named "Directory" or "User" in those places:

"/profile\AppData\Roaming\GPSoftware\Directory Opus\User Data\CROP\cropAnimFrames.exe" -i {sourcepath$|noterm}

Could also shorten it to this:

"/dopusdata\User Data\CROP\cropAnimFrames.exe" -i {sourcepath$|noterm}
1 Like