In addition to the options common to all programs based on libnetpbm (most notably -quiet, see Common
Options ), pnmcrop recognizes the following command line options:
-white Take white to be the background color. pnmcrop removes borders which are white.
You may specify at most one of -black, -white, -sides, -bg-color, and -bg-corner.
-black Take black to be the background color. pnmcrop removes borders which are black.
You may specify at most one of -black, -white, -sides, -bg-color, and -bg-corner.
-bg-color=color
This tells pnmcrop what color is the background - it will crop areas of this color. color is a
value that would be used as the argument of the pnm_parsecolor() library routine .
You may specify at most one of -black, -white, -sides, -bg-color, and -bg-corner.
This option was new in Netpbm 10.86 (March 2019).
-sides Determine the background color from the colors of the four corners of the input image. pnmcrop
removes borders which are of the background color.
If at least three of the four corners are the same color, pnmcrop takes that as the background
color. If not, pnmcrop looks for two corners of the same color in the following order, taking the
first found as the background color: top, left, right, bottom. If all four corners are different
colors, pnmcrop assumes an average of the four colors as the background color.
The -sides option slows pnmcrop down, as it reads the entire image to determine the background
color in addition to the up to three times that it would read it without -sides.
You may specify at most one of -black, -white, -sides, -bg-color, and -bg-corner.
-bg-corner={topleft|topright|bottomleft|bottomright
This option indicates a corner which is background. pnmcrop will use the color of this corner as
the background color and crop edges of that color.
You may specify at most one of -black, -white, -sides, -bg-color, and -bg-corner.
This option was new in Netpbm 10.86 (March 2019).
-left Remove any left border.
-right Remove any right border.
-top Remove any top border.
-bottom
Remove any bottom border.
-margin=pixels
Leave pixels pixels of border. Expand the border to this size if necessary.
This option was new in Netpbm 10.29 (August 2005).
-closeness=closeness_percent
Any color in the image that is at least this close to the operative background color is considered
to be background.
You can use this if the image has borders that vary slightly in color, such as would be the case
in a photograph. Consider a photograph against a white screen. The color of the screen varies
slightly with shading and dirt and such, but is still quite distinct in color from the subject of
the photograph. pnmcrop will choose some particular shade as the background color and if you
specify an appropriate -closeness value, it will correctly identify all of the screen as
background and crop it off.
To implement more complex rules for identifying background, use -borderfile.
The default is zero, which means a pixel's color must exactly match the background color for the
pixel to be considered part of a background border.
This option was new in Netpbm 10.78 (March 2017). With older Netpbm, colors must match exactly.
-borderfile=filename
Use the image in the file named filename instead of the input image to determine where the borders
of the input image are and the background color.
Without this option, pnmcrop examines the input image and figures out what part of the image is
border and what part is foreground (not border), as well as the background color. With this
option, pnmcrop finds the borders in one image, then uses the those four border sizes (left,
right, top, bottom) in cropping a different image. Furthermore, if you use -margin to add
borders, the color of those borders is the background color pnmcrop detects in the border file.
The point of this is that you may want to help pnmcrop to come to a different conclusion as to
where the borders are and what the background color is by preprocessing the input image. For
example, consider an image that has speckles of noise in its borders. pnmcrop isn't smart enough
to recognize these as noise; it sees them as foreground image. So pnmcrop considers most of your
borders to be foreground and does not crop them off as you want. To fix this, run the image
through a despeckler such as pbmclean and tell pnmcrop to use the despeckled version of the image
as the -borderfile image, but the original speckled version as the input image. That way, you
crop the borders, but retain the true foreground image, speckles and all.
The border file must have the same number of images in it as the input file; the background color
determination for image N of the input is based on the image N of the border file.
This option was new in Netpbm 10.29 (August 2005).
Before Netpbm 10.46 (March 2009), the original image and not the border file determines the
background color. pnmcrop fails if there is no apparent background color in the original image
(i.e. the corners of the image don't have a common color).
-blank-image={abort|pass|minimize|maxcrop}
This determines how pnmcrop handles an image which is entirely
background (blank), a case where cropping doesn't make much sense.
abort
program fails, with explanatory message (default)
pass
Output image is the same as the input image.
-margin has no effect.
minimize
output is a single row, column, or pixel (of the background color).
If you crop both vertically and horizontally (the default), it is a
single pixel. If you crop only vertically, a single row, of the
original width. If you crop only horizontally, it is a single column,
of the original height.
This is a somewhat incongruous result; the mathematically consistent
result of cropping the background from an image that is entirely
background would be an image with no pixels at all. But such a thing
does not exist in the Netpbm formats (and you probably wouldn't want
it anyway, because whoever processes this output may not tolerate
that).
The background can be more than one color when you specify
-closeness, so it matters which row, column, or pixel remains.
If you crop on the top and not bottom, it is the last row that remains.
If you crop on both the top and bottom, it is the middle row that
remains. The other cases follow similarly.
If you specify a margin (-margin), the output image consists
entirely of the margins; there is no single row, column, or pixel
between the margins. So with -margin, the incongruity
mentioned above does not exist. But before Netpbm 10.92 (September
2020), -margin was ignored with -blank-image=minimize.
maxcrop
This odd function selects a hypothetical cropping which is not even
possible, and therefore is valid only with -reportfull or
-reportsize. The cropping that this selects is a crop of the
entire image on every side on which you request cropping. So if you
request cropping only on the left, of a 600 pixel wide image, this
selects a cropping of 600 pixels from the left and none from the other
three sides. Note that were this cropping actually applied, this would
produce an image with no pixels, which is not a valid Netpbm image. But
it gets stranger still if you request cropping on both the right and the
left. In that case, the cropping selected is a cropping of 600 pixels
from both the right and left sides, which would leave a negative-width
image.
This is actually useful if you are trying to find a single set of
cropping parameters to crop a stream of images. To do this, you could
do a pass with -reportsize and -blank-image=maxcrop to
compute the maximum crop for each edge, and then use those numbers in
-cropxxxoptionsonapamcutpasstodothecrop.Inthisscenario,anyall-background(blank)imageswouldhavenoeffectonthecroppingparametersyoucompute.Ifyoudothis,youmustgivespecialconsiderationtoastreamwithnothingbutblankimages.-marginisalwaysignoredwhentheimageisallbackground.ThisoptionwasnewinNetpbm10.86(March2019).-reportfull
With this option, pnmcrop does not actually crop anything. Instead, it just prints to Standard
Output parameters of the cropping it would have done. The output is a single line per image, like
in this example:
0 +7 -20 -10 200 300 rgb-255:10/0/255 0.0
The line is composed of the following blank-delimited tokens:
• how many pixels would be cropped or padded on the left. This is
a signed decimal number, where + means pad and - means crop. If there
would be no change, this is unsigned zero.
• same, but for the right side.
• same, but for the top.
• same, but for the bottom.
• the resulting image width in pixels, in decimal.
• the resulting image height in pixels, in decimal.
• The color pnmcrop took to be the background color, like
'rgb-255:10/0/255' (This is a format recognized by
the pnm_parsecolor()
library routine). The maxval in the color specification is the maxval of
the image.
• The closeness value (see -closeness option) pnmcrop
used, in floating point decimal.
You cannot use -borderfile together with this option.
This option was new in Netpbm 10.86 (March 2019).
-reportsize
This is like -reportfull, but reports only the left, right, top, bottom, width, and height.
You cannot use -borderfile together with this option.
This option was new in Netpbm 10.86 (March 2019).
-verbose
Print on Standard Error information about the processing, including exactly how much is being
cropped off of which sides.