Copyright © Fred Weinhaus My scripts are available free of charge for non-commercial (non-profit) use, ONLY. For use of my scripts in commercial (for-profit) environments or non-free applications, please contact me (Fred Weinhaus) for licensing arrangements. My email address is fmw at alink dot net. If you: 1) redistribute, 2) incorporate any of these scripts into other free applications or 3) reprogram them in another scripting language, then you must contact me for permission, especially if the result might be used in a commercial or for-profit environment. Usage, whether stated or not in the script, is restricted to the above licensing arrangements. It is also subject, in a subordinate manner, to the ImageMagick license, which can be found at: http://www.imagemagick.org/script/license.php Please read the Pointers For Use on my home page to properly install and customize my scripts. |
Automatically trims the outside of an image or crops the inside of a rotated image. |
last modified: December 15, 2018
USAGE: autotrim [-m mode] [-f fuzzval] [-c coords] [-C color] [-l left]
[-r right ] [-t top ] [-b bottom ] [-p preview] infile outfile
-m .... mode ....... mode of trim; options are outer (o) or PURPOSE: Automatically trims the outside of an image or crops the inside of a rotated image. DESCRIPTION: AUTOTRIM automatically trims a (nearly) uniform color border around an image. If the image is rotated, one can trim to the bounding box around the image area or alternately trim to the maximum central area that contains no border pixels. The excess border does not have to completely surround the image. It may be only on one side. However, one must identify a coordinate within the border area for the algorithm to extract the base border color and also specify a fuzz value when the border color is not uniform. For simple border trimming of a normally oriented image or the bounding box of a rotated image, you may err somewhat towards larger than optimal fuzz values. For images that contain rotated picture data, when you want to trim to the central area, you should choose the smallest fuzz value that is appropriate. If the result is off a little, you may use the left/right/top/bottom arguments to adjust the automatically determined trim region. ARGUMENTS: -m mode ... MODE of trim. The options are either outer (o) or inner (i). The default=outer. -f fuzzval --- FUZZVAL is the fuzz amount specified as a percent 0 to 100 (without the % sign). The default is zero which indicates that border is a uniform color. Larger values are needed when the border is not a uniform color. -C color ... COLOR of border or background. Any valid IM color is allowed. The default is to use coords to get color. -c coords --- COORDS is any location within the border area for the algorithm to find the base border color. It may be specified in terms of gravity parameters (NorthWest, North, NorthEast, East, SouthEast, South, SouthWest or West) or as a pixel coordinate "x,y". The default is the upper left corner = NorthWest = "0,0". -l left --- LEFT is the number of extra pixels to shift the trim of the left edge of the image. The trim is shifted right/left for +/- integer values. The default=0. -r right --- RIGHT is the number of extra pixels to shift the trim of the right edge of the image. The trim is shifted right/left for +/- integer values. The default=0. -t top --- TOP is the number of extra pixels to shift the trim of the top edge of the image. The trim is shifted down/up for +/- integer values. The default=0. -b bottom --- BOTTOM is the number of extra pixels to shift the trim of the bottom edge of the image. The trim is shifted down/up for +/- integer values. The default=0. -p preview ... PREVIEW displays a red box on the input image. The choices are: viewonly (vo), view (v), saveonly (so), save (s) or off (o). The default=off. If viewonly or saveonly is selected, then no cropped output image will be generated. The preview image, if saved, will be named from the infile as inname_preview.suffix CAVEAT: No guarantee that this script will work on all platforms, nor that trapping of inconsistent parameters is complete and foolproof. Use At Your Own Risk. |
Trim Of Square Image With Uniform Border Color |
|||||
2 Pixel White Border |
2 Pixel Black Border |
2 Pixel White Right Edge |
2 Pixel Black Right Edge |
||
Arguments: |
Arguments: |
Arguments: |
Arguments: |
||
Trim Of Square Image With Non-Uniform Border Color |
|||||
5 Pixel Radial |
Arguments: |
Arguments: |
Arguments: |
Arguments: |
|
Trim Of Rotated Image To Bounding Region |
|||||
Rotated Image |
Arguments: |
||||
Trim To Center Area Of Rotated Square Image |
|||||
Rotated 45 deg |
Rotated -20 deg |
Rotated 10 deg |
Rotated -5 deg |
Rotated 2 deg |
|
Arguments: |
Arguments: |
Arguments: |
Arguments: |
Arguments: |
|
Trim To Center Area Of Rotated Rectangular Image |
|||||
Rotated 45 deg |
Rotated -20 deg |
Rotated 10 deg |
Rotated -5 deg |
||
Arguments: |
Arguments: |
Arguments: |
Arguments: |
||
What the script does is as follows for an inner crop:
See script for details |