Linux Commands Examples

A great documentation place for Linux commands


crop a portable anymap

see also : pnmcut - pnmfile


pnmcrop [-white|-black|-sides] [-left] [-right] [-top] [-bottom] [pnmfile]

All options may be abbreviated to their shortest unique prefix or specified with double hyphens.

add an example, a script, a trick and tips

: email address (won't be displayed)
: name

Step 2

Thanks for this example ! - It will be moderated and published shortly.

Feel free to post other examples
Oops ! There is a tiny cockup. A damn 404 cockup. Please contact the loosy team who maintains and develops this wonderful site by clicking in the mighty feedback button on the side of the page. Say what happened. Thanks!


    < $ | pnmcrop > $base.ppm__
pnmpaste $base.ppm__ 0 0 $base.ppm_ | pnmcrop > $base.ppm
convert $base.ppm sgi:$base.rgb
( pngtopnm < "$1" | pnmcrop | ppmchange black white white black | pnmtopng -transparent black > "$1".tmp ) 2>/dev/null
#( pngtopnm < "$1" | pnmcrop | pnmtopng -transparent white > "$1".tmp ) 2>/dev/null
date >> $LOGFILE
( pngtopnm < "$1" | pnmcrop | pnmtopng -transparent white > "$1".tmp ) >> $LOGFILE 2>&1
pnmcrop < $1.ppm | ppmtogif > $1.gif
rm *.ppm


Reads a PBM, PGM, or PPM image as input. Removes borders that are the background color, and produces the same type of image as output.

If you don’t specify otherwise, pnmcrop assumes the background color is whatever color the top left and right corners of the image are and if they are different colors, something midway between them. You can specify that the background is white or black with the -white and -black options or make pnmcrop base its guess on all four corners instead of just two with -sides.

By default, pnmcrop chops off any stripe of background color it finds, on all four sides. You can tell pnmcrop to remove only specific borders with the -left, -right, -top, and -bottom options.

If you want to chop a specific amount off the side of an image, use pnmcut.

If you want to add different borders after removing the existing ones, use pnmcat or pnmcomp.



Take white to be the background color. pnmcrop removes borders which are white.


Take black to be the background color. pnmcrop removes borders which are black.


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.


Remove any left border.


Remove any right border.


Remove any top border.


Remove any bottom border.


Print on Standard Error information about the processing, including exactly how much is being cropped off of which sides.

see also

pnmcut , pnmfile , pnm


Copyright (C) 1989 by Jef Poskanzer.

How can this site be more helpful to YOU ?

give  feedback