How do I crop/resize a background/border out of an image with GraphicsMagick -
i have images in large set of images have white (or black) border surrounds image itself. how can i...
- crop image size without said background/border
- resize image fill given output size centered.
for example, have uploaded image 1280x1024px in size, has white (or black) border interior size 800x700 (may not centered), want crop out border, resize fill 640x480 output. take interior image, fill 640x480 cropping additional 100px of height original.
i'd prefer can batch/shell script graphics magick, accept solution via phantomjs well. i'd prefer avoid additional tools/languages if @ possible.
trim remove borders according corners pixels,
extent , gravity make image size , align accordingly,
also see geometry parameters,
convert -trim source.png trim.png convert -extent 800x600 -gravity center trim.png frame.png
here dimensions of images shown :
- source : 722 x 480
- trim : 640 x 400
- frame : 800x 600
edit
this resize image fit 800 pixels wide, , make height 600 if less:
convert -resize 800x600^ -extent 800x600 -gravity center trim.png resize.png
see http://www.imagemagick.org/usage/resize/#fill details, particulary should test how behaves on portrait images.
also, if remove 800 @ resize
parameter, fit height :
convert -resize x600^ -extent 800x600 -gravity center trim.png resize.png
edit 2
you must use caret 1 of axes :
convert -resize 1200^ -extent 1200x600 -gravity center trim.png resize1.png
as can see, top , bottom have been trimmed , image fitted according width.
Comments
Post a Comment