-
ImageMagick version7.x Operating system, version and so onWindows 10 DescriptionI have a fair amount of files which need to be auto-cropped.
I'm not terribly fluent in batch scripting to begin with. I can imagine what I want to do in terms of image editing: Copy current layer to new layer, do filters on new layer, use new layer as a reference while performing operations on all layers, delete new layer. In vague pseudocode I have: Could someone take that and put it into good ol' (There seem to be a couple bash scripts which are geared towards what I'm looking for, but the current Ubuntu LTS only provides ImageMagick 6.x, attempting to manually install 7.x left me in dependency hell, and every time I've tried cygwin/MinGW/etc on Windows it's ended up in unbelievable frustration, so I'm going to stick with crappy old Windows batch until the "user-friendly" Linux distro finds a way to handle dependencies at least as gracefully as DirectX on Windows 95 did thirty years ago) |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 7 replies
-
Can you post an example image? One often can either use other noise filters (see sequence of multiple -enhance filters) or threshold the image and remove items smaller than some area. Then find the crop values (see %@ string format). The crop the original with those crop values. |
Beta Was this translation helpful? Give feedback.
-
If doing this in a BAT file, double % to %% in %%A and %@, but not in %MYTRIM%. You can put those commands in a for loop to process all PNG files in the current directory like this:
Note that I put the output files in a different directory, which must already exist. If I put them in the same directory then the output files would also be processed as input files. EDIT: The two commands can be combined into one, like this:
|
Beta Was this translation helpful? Give feedback.
-
Yeah, my fault, I got it a bit wrong. I had a nagging feeling something was wrong, but couldn't see what.
Note the new first line and the change to The problem is that the Windows interpreter only translates Sorry. (Still no guarantees I've now got it right.) |
Beta Was this translation helpful? Give feedback.
Yeah, my fault, I got it a bit wrong. I had a nagging feeling something was wrong, but couldn't see what.
Note the new first line and the change to
!MYTRIM!
.The problem is that the Windows interpreter only translates
%MYTRIM%
once, so the value isn't updated in the loop.!MYTRIM!
is re-translated every time in the loop, aka "delayed expansion".Sorry. (Still no guarantees I've now got it right.)