I use 6.8.1 q16
Is it possible to crop 15px from the right side, 5 px from top, 25 from bottom and 10 from the left side? I use a SP3000 scanner and it leaves mask on all four side, i would like to do a batch job. Thanks.
Cropping all four sides differently
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Cropping all four sides differently
Create a command with mogrify or convert using -chop 4 times. See https://www.imagemagick.org/Usage/crop/#chop
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: Cropping all four sides differently
... Or do it in a single "-crop", with fx expressions:
Code: Select all
magick in.tiff -crop %[fx:w-25]x%[fx:h-30]+10+5 +repage out.tiff
snibgo's IM pages: im.snibgo.com
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Cropping all four sides differently
Snibgo's command will require IM 7. It won't work on IM 6. But you can create the width and height arguments in IM 6 in separate steps putting them in variables and then use the variables in the crop command.
Unix syntax:
Unix syntax:
Code: Select all
width=`convert -ping input.suffix -format "%[fx:w-25]" info:`
height=`convert -ping input.suffix -format "%[fx:h-30]" info:`
convert input.suffix -crop ${width}x${height}+10+5 +repage out.suffix
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: Cropping all four sides differently
Thanks, Fred, I didn't notice:
Misko78 wrote:I use 6.8.1
snibgo's IM pages: im.snibgo.com
- GeeMack
- Posts: 718
- Joined: 2015-12-01T22:09:46-07:00
- Authentication code: 1151
- Location: Central Illinois, USA
Re: Cropping all four sides differently
You can make a Windows BAT script that uses one ImageMagick command to do the calculations and reset the canvas dimensions to create that result.
Code: Select all
convert input.png -set page "%%[fx:w-10-15]x%%[fx:h-5-25]-10-5" -flatten output.png
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Cropping all four sides differently
Nice approach for IM 6, GeeMack!
Another IM 6 approach would be to use distort SRT with viewport cropping.
See https://www.imagemagick.org/Usage/disto ... t_viewport
Another IM 6 approach would be to use distort SRT with viewport cropping.
See https://www.imagemagick.org/Usage/disto ... t_viewport