1Pnmcrop User Manual(0) Pnmcrop User Manual(0)
2
3
4
6 pnmcrop - crop a Netpbm image
7
8
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
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
55 instead 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
83 ignored 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
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
139 image 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.
186 pnmcrop will choose some particular shade as the background
187 color and if you specify an appropriate -closeness value, it
188 will correctly identify all of the screen as background and crop
189 it off.
190
191 To implement more complex rules for identifying background, use
192 -borderfile.
193
194 The default is zero, which means a pixel's color must exactly
195 match the background color for the pixel to be considered part
196 of a background border.
197
198 This option was new in Netpbm 10.78 (March 2017). With older
199 Netpbm, colors must match exactly.
200
201
202 -borderfile=filename
203 Use the image in the file named filename instead of the input
204 image to determine where the borders of the input image are and
205 the background color.
206
207 Without this option, pnmcrop examines the input image and fig‐
208 ures out what part of the image is border and what part is fore‐
209 ground (not border), as well as the background color. With this
210 option, pnmcrop finds the borders in one image, then uses the
211 those four border sizes (left, right, top, bottom) in cropping a
212 different image. Furthermore, if you use -margin to add bor‐
213 ders, the color of those borders is the background color pnmcrop
214 detects in the border file.
215
216 The point of this is that you may want to help pnmcrop to come
217 to a different conclusion as to where the borders are and what
218 the background color is by preprocessing the input image. For
219 example, consider an image that has speckles of noise in its
220 borders. pnmcrop isn't smart enough to recognize these as
221 noise; it sees them as foreground image. So pnmcrop considers
222 most of your borders to be foreground and does not crop them off
223 as you want. To fix this, run the image through a despeckler
224 such as pbmclean and tell pnmcrop to use the despeckled version
225 of the image as the -borderfile image, but the original speckled
226 version as the input image. That way, you crop the borders, but
227 retain the true foreground image, speckles and all.
228
229 The border file must have the same number of images in it as the
230 input file; the background color determination for image N of
231 the input is based on the image N of the border file.
232
233 This option was new in Netpbm 10.29 (August 2005).
234
235 Before Netpbm 10.46 (March 2009), the original image and not the
236 border file determines the background color. pnmcrop fails if
237 there is no apparent background color in the original image
238 (i.e. the corners of the image don't have a common color).
239
240
241 -blank-image={abort|pass|minimize|maxcrop}
242 This determines how pnmcrop handles an image which is entirely
243 background (blank), a case where cropping doesn't make much
244 sense.
245
246
247
248 abort
249
250 program fails, with explanatory message (default)
251
252
253 pass
254
255 Output image is the same as the input image.
256 -margin has no effect.
257
258
259 minimize
260
261 output is a single row, column, or pixel (of the background
262 color).
263 If you crop both vertically and horizontally (the
264 default), it is a
265 single pixel. If you crop only vertically, a single row,
266 of the
267 original width. If you crop only horizontally, it is a
268 single column,
269 of the original height.
270
271 This is a somewhat incongruous result; the mathematically con‐
272 sistent
273 result of cropping the background from an image that is
274 entirely
275 background would be an image with no pixels at all. But
276 such a thing
277 does not exist in the Netpbm formats (and you probably
278 wouldn't want
279 it anyway, because whoever processes this output may not
280 tolerate
281 that).
282
283 The background can be more than one color when you specify
284 -closeness, so it matters which row, column, or pixel
285 remains.
286 If you crop on the top and not bottom, it is the last row
287 that remains.
288 If you crop on both the top and bottom, it is the middle
289 row that
290 remains. The other cases follow similarly.
291
292 If you specify a margin (-margin), the output image consists
293 entirely of the margins; there is no single row, column,
294 or pixel
295 between the margins. So with -margin, the incongruity
296 mentioned above does not exist. But before Netpbm 10.92
297 (September
298 2020), -margin was ignored with -blank-image=minimize.
299
300
301 maxcrop
302
303 This odd function selects a hypothetical cropping which is not
304 even
305 possible, and therefore is valid only with -reportfull or
306 -reportsize. The cropping that this selects is a crop of
307 the
308 entire image on every side on which you request cropping.
309 So if you
310 request cropping only on the left, of a 600 pixel wide
311 image, this
312 selects a cropping of 600 pixels from the left and none
313 from the other
314 three sides. Note that were this cropping actually
315 applied, this would
316 produce an image with no pixels, which is not a valid
317 Netpbm image. But
318 it gets stranger still if you request cropping on both the
319 right and the
320 left. In that case, the cropping selected is a cropping
321 of 600 pixels
322 from both the right and left sides, which would leave a
323 negative-width
324 image.
325
326 This is actually useful if you are trying to find a single
327 set of
328 cropping parameters to crop a stream of images. To do
329 this, you could
330 do a pass with -reportsize and -blank-image=maxcrop to
331 compute the maximum crop for each edge, and then use those
332 numbers in
333 -cropxxx options on a pamcut pass to do the crop.
334 In this scenario, any all-background (blank) images would
335 have no effect
336 on the cropping parameters you compute. If you do this,
337 you must give
338 special consideration to a stream with nothing but blank
339 images.
340
341
342
343 -margin is always ignored when the image is all background.
344
345 This option was new in Netpbm 10.86 (March 2019).
346
347
348 -reportfull
349 With this option, pnmcrop does not actually crop anything.
350 Instead, it just prints to Standard Output parameters of the
351 cropping it would have done. The output is a single line per
352 image, like in this example:
353
354 <span style="font-family: monospace;">
355 0 +7 -20 -10 200 300 rgb-255:10/0/255 0.0
356 </span>
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,
411 including exactly how much is being cropped off of which sides.
412
413
414
415
417 pamcut(1), pamfile(1), pnm(1)
418
419
421 Copyright (C) 1989 by Jef Poskanzer.
422
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)