1Pnmcrop User Manual(0)                                  Pnmcrop User Manual(0)
2
3
4

NAME

6       pnmcrop - crop a Netpbm image
7
8

SYNOPSIS

10       pnmcrop
11
12       [-white      |-black     |-sides     |-bg-color=color     |-bg-corner={
13       topleft|topright|bottomleft|bottomright} ]
14
15       [-left]
16
17       [-right]
18
19       [-top]
20
21       [-bottom]
22
23       [-margin=pixels]
24
25       [-closeness=closeness_percent]
26
27       [-borderfile=filename]
28
29       [-blank-image={abort|pass|minimize|maxcrop}]
30
31       {[-reportfull]|[-reportsize]}
32
33       [-verbose]
34
35       [pnmfile]
36
37       Minimum unique abbreviation of option is acceptable.  You may use  dou‐
38       ble  hyphens  instead  of single hyphen to denote options.  You may use
39       white space in place of the equals sign to separate an option name from
40       its value.
41
42

DESCRIPTION

44       This program is part of Netpbm(1).
45
46       pnmcrop  reads  a PBM, PGM, or PPM image as input, removes borders that
47       are the background color, and produces the same type of image  as  out‐
48       put.
49
50       If you don't specify otherwise, pnmcrop assumes the background color is
51       whatever color the top left and right corners of the image are  and  if
52       they  are  different  colors,  something  midway between them.  You can
53       specify that the background is white  or  black  with  the  -white  and
54       -black  options  or make pnmcrop base its guess on all four corners in‐
55       stead of just two with -sides.
56
57       By default, pnmcrop chops off any stripe of background color it  finds,
58       on  all  four sides.  You can tell pnmcrop to remove only specific bor‐
59       ders with the -left, -right,
60         -top, and -bottom options.
61
62       But note that pnmcrop's determination of the background color is  inde‐
63       pendent of which edges you crop, which may not be intuitive.  For exam‐
64       ple, imagine an image with a blue border at the top and a black  border
65       at  the  bottom and you say to crop the bottom (-bottom).  You may have
66       expected to crop the black border, but you  actually  won't  crop  any‐
67       thing,  because  pnmcrop  considers the background color to be whatever
68       color the top two corners are, which is blue, and there is no  blue  at
69       the bottom of the image.  If you do want pnmcrop to take the background
70       color from the edges being cropped, use -bg-corner.
71
72
73       If you want to leave some border, use the -margin option.  It will  not
74       only  spare  some  of  the border from cropping, but will fill in (with
75       what pnmcrop considers the background color) if necessary to get up  to
76       that size.
77
78       If  the input is a multi-image stream, pnmcrop processes each one inde‐
79       pendently and produces a multi-image  stream  as  output.   It  chooses
80       where  to  crop  independently  for each image.  So if you start with a
81       stream of images of the same dimensions, you may end up with images  of
82       differing dimensions.  Before Netpbm 10.37 (December 2006), pnmcrop ig‐
83       nored all input images but the first.
84
85       If you want to chop a specific amount off the side  of  an  image,  use
86       pamcut.
87
88       If  you want to add different borders after removing the existing ones,
89       use pnmcat or pamcomp.
90
91
92

OPTIONS

94       In addition to the options common to all programs  based  on  libnetpbm
95       (most notably -quiet, see
96        Common  Options  ⟨index.html#commonoptions⟩  ), pnmcrop recognizes the
97       following command line options:
98
99
100
101       -white Take white to be the background color.  pnmcrop removes  borders
102              which are white.
103
104              You  may  specify  at  most  one of -black, -white, -sides, -bg-
105              color, and -bg-corner.
106
107
108       -black Take black to be the background color.  pnmcrop  removes borders
109              which are black.
110
111              You  may  specify  at  most  one of -black, -white, -sides, -bg-
112              color, and -bg-corner.
113
114
115       -bg-color=color
116              This tells pnmcrop what color is the background - it  will  crop
117              areas of this color.  color is a value that would be used as the
118              argument    of    the    pnm_parsecolor()    library     routine
119              ⟨libnetpbm_image.html#colorname⟩ .
120
121              You  may  specify  at  most  one of -black, -white, -sides, -bg-
122              color, and -bg-corner.
123
124              This option was new in Netpbm 10.86 (March 2019).
125
126
127       -sides Determine the background color from the colors of the four  cor‐
128              ners  of  the input image.  pnmcrop removes borders which are of
129              the background color.
130
131              If at least three of the four corners are the same  color,  pnm‐
132              crop  takes that as the background color.  If not, pnmcrop looks
133              for two corners of the same color in the following order, taking
134              the  first found as the background color: top, left, right, bot‐
135              tom.  If all four corners are different colors, pnmcrop  assumes
136              an average of the four colors as the background color.
137
138              The -sides option slows pnmcrop down, as it reads the entire im‐
139              age to determine the background color in addition to the  up  to
140              three times that it would read it without -sides.
141
142              You  may  specify  at  most  one of -black, -white, -sides, -bg-
143              color, and -bg-corner.
144
145
146       -bg-corner={topleft|topright|bottomleft|bottomright
147              This option indicates a corner  which  is  background.   pnmcrop
148              will  use  the  color of this corner as the background color and
149              crop edges of that color.
150
151              You may specify at most one  of  -black,  -white,  -sides,  -bg-
152              color, and -bg-corner.
153
154              This option was new in Netpbm 10.86 (March 2019).
155
156
157       -left  Remove any left border.
158
159
160       -right Remove any right border.
161
162
163       -top   Remove any top border.
164
165
166       -bottom
167              Remove any bottom border.
168
169
170       -margin=pixels
171              Leave  pixels  pixels of border.  Expand the border to this size
172              if necessary.
173
174              This option was new in Netpbm 10.29 (August 2005).
175
176
177       -closeness=closeness_percent
178              Any color in the image that is at least this close to the opera‐
179              tive background color is considered to be background.
180
181              You  can use this if the image has borders that vary slightly in
182              color, such as would be the case in a  photograph.   Consider  a
183              photograph  against  a  white  screen.   The color of the screen
184              varies slightly with shading and dirt and  such,  but  is  still
185              quite distinct in color from the subject of the photograph.  pn‐
186              mcrop will choose some particular shade as the background  color
187              and if you specify an appropriate -closeness value, it will cor‐
188              rectly identify all of the screen as background and crop it off.
189
190              To implement more complex rules for identifying background,  use
191              -borderfile.
192
193              The  default  is  zero, which means a pixel's color must exactly
194              match the background color for the pixel to be  considered  part
195              of a background border.
196
197              This  option  was  new in Netpbm 10.78 (March 2017).  With older
198              Netpbm, colors must match exactly.
199
200
201       -borderfile=filename
202              Use the image in the file named filename instead  of  the  input
203              image  to determine where the borders of the input image are and
204              the background color.
205
206              Without this option, pnmcrop examines the input image  and  fig‐
207              ures out what part of the image is border and what part is fore‐
208              ground (not border), as well as the background color.  With this
209              option,  pnmcrop  finds  the borders in one image, then uses the
210              those four border sizes (left, right, top, bottom) in cropping a
211              different  image.   Furthermore,  if you use -margin to add bor‐
212              ders, the color of those borders is the background color pnmcrop
213              detects in the border file.
214
215              The  point  of this is that you may want to help pnmcrop to come
216              to a different conclusion as to where the borders are  and  what
217              the  background  color is by preprocessing the input image.  For
218              example, consider an image that has speckles  of  noise  in  its
219              borders.   pnmcrop  isn't  smart  enough  to  recognize these as
220              noise; it sees them as foreground image.  So  pnmcrop  considers
221              most of your borders to be foreground and does not crop them off
222              as you want.  To fix this, run the image  through  a  despeckler
223              such  as pbmclean and tell pnmcrop to use the despeckled version
224              of the image as the -borderfile image, but the original speckled
225              version as the input image.  That way, you crop the borders, but
226              retain the true foreground image, speckles and all.
227
228              The border file must have the same number of images in it as the
229              input  file;  the  background color determination for image N of
230              the input is based on the image N of the border file.
231
232              This option was new in Netpbm 10.29 (August 2005).
233
234              Before Netpbm 10.46 (March 2009), the original image and not the
235              border  file  determines the background color.  pnmcrop fails if
236              there is no apparent background  color  in  the  original  image
237              (i.e. the corners of the image don't have a common color).
238
239
240       -blank-image={abort|pass|minimize|maxcrop}
241              This determines how pnmcrop handles an image which is entirely
242                background  (blank),  a  case where cropping doesn't make much
243              sense.
244
245
246
247       abort
248
249              program fails, with explanatory message (default)
250
251
252       pass
253
254              Output image is the same as the input image.
255                    -margin has no effect.
256
257
258       minimize
259
260              output is a single row, column,  or  pixel  (of  the  background
261              color).
262                    If  you  crop  both  vertically  and horizontally (the de‐
263              fault), it is a
264                    single pixel.  If you crop only vertically, a single  row,
265              of the
266                    original  width.   If  you crop only horizontally, it is a
267              single column,
268                    of the original height.
269
270              This is a somewhat incongruous result; the  mathematically  con‐
271              sistent
272                      result  of cropping the background from an image that is
273              entirely
274                      background would be an image with no pixels at all.  But
275              such a thing
276                      does  not  exist in the Netpbm formats (and you probably
277              wouldn't want
278                      it anyway, because whoever processes this output may not
279              tolerate
280                      that).
281
282              The background can be more than one color when you specify
283                    -closeness,  so it matters which row, column, or pixel re‐
284              mains.
285                    If you crop on the top and not bottom, it is the last  row
286              that remains.
287                    If  you  crop on both the top and bottom, it is the middle
288              row that
289                    remains.  The other cases follow similarly.
290
291              If you specify a margin (-margin), the output image consists
292                      entirely of the margins; there is no single row, column,
293              or pixel
294                      between the margins.  So with -margin, the incongruity
295                      mentioned above does not exist.  But before Netpbm 10.92
296              (September
297                      2020), -margin was ignored with -blank-image=minimize.
298
299
300       maxcrop
301
302              This odd function selects a hypothetical cropping which  is  not
303              even
304                    possible, and therefore is valid only with -reportfull or
305                    -reportsize.   The cropping that this selects is a crop of
306              the
307                    entire image on every side on which you request  cropping.
308              So if you
309                    request cropping only on the left, of a 600 pixel wide im‐
310              age, this
311                    selects a cropping of 600 pixels from the  left  and  none
312              from the other
313                    three  sides.   Note  that were this cropping actually ap‐
314              plied, this would
315                    produce an image with no pixels,  which  is  not  a  valid
316              Netpbm image.  But
317                    it gets stranger still if you request cropping on both the
318              right and the
319                    left.  In that case, the cropping selected is  a  cropping
320              of 600 pixels
321                    from  both  the  right and left sides, which would leave a
322              negative-width
323                    image.
324
325                    This is actually useful if you are trying to find a single
326              set of
327                    cropping  parameters  to  crop  a stream of images.  To do
328              this, you could
329                    do a pass with -reportsize and -blank-image=maxcrop to
330                    compute the maximum crop for each edge, and then use those
331              numbers in
332                    -cropxxx options on a pamcut pass to do the crop.
333                    In  this scenario, any all-background (blank) images would
334              have no effect
335                    on the cropping parameters you compute.  If you  do  this,
336              you must give
337                    special  consideration  to a stream with nothing but blank
338              images.
339
340
341
342              -margin is always ignored when the image is all background.
343
344              This option was new in Netpbm 10.86 (March 2019).
345
346
347       -reportfull
348              With this option, pnmcrop does not actually crop anything.   In‐
349              stead, it just prints to Standard Output parameters of the crop‐
350              ping it would have done.  The output is a single line per image,
351              like in this example:
352
353
354                   0 +7 -20 -10 200 300 rgb-255:10/0/255 0.0
355
356
357
358              The line is composed of the following blank-delimited tokens:
359
360
361
362       •      how many pixels would be cropped or padded on the left.  This is
363                  a signed decimal number, where + means pad and - means crop.
364              If there
365                  would be no change, this is unsigned zero.
366
367
368       •      same, but for the right side.
369
370
371       •      same, but for the top.
372
373
374       •      same, but for the bottom.
375
376
377       •      the resulting image width in pixels, in decimal.
378
379
380       •      the resulting image height in pixels, in decimal.
381
382
383       •      The color pnmcrop took to be the background color, like
384                 'rgb-255:10/0/255' (This is a format recognized by
385                 the pnm_parsecolor() ⟨libnetpbm_image.html#colorname⟩
386                 library routine).  The maxval in the color  specification  is
387              the maxval of
388                 the image.
389
390
391       •      The closeness value (see -closeness option) pnmcrop
392                 used, in floating point decimal.
393
394
395              You cannot use -borderfile together with this option.
396
397              This option was new in Netpbm 10.86 (March 2019).
398
399
400       -reportsize
401              This is like -reportfull, but reports only the left, right, top,
402              bottom, width, and height.
403
404              You cannot use -borderfile together with this option.
405
406              This option was new in Netpbm 10.86 (March 2019).
407
408
409       -verbose
410              Print on Standard Error information about  the  processing,  in‐
411              cluding exactly how much is being cropped off of which sides.
412
413
414
415

SEE ALSO

417       pamcut(1), pamfile(1), pnm(1)
418
419

AUTHOR

421       Copyright (C) 1989 by Jef Poskanzer.
422

DOCUMENT SOURCE

424       This  manual  page was generated by the Netpbm tool 'makeman' from HTML
425       source.  The master documentation is at
426
427              http://netpbm.sourceforge.net/doc/pnmcrop.html
428
429netpbm documentation            16 August 2020          Pnmcrop User Manual(0)
Impressum