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...

  1. crop image size without said background/border
  2. 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 

enter image description here

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:

enter image description here

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 :

enter image description here

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 

enter image description here

as can see, top , bottom have been trimmed , image fitted according width.


Comments

Popular posts from this blog

javascript - how to protect a flash video from refresh? -

android - Associate same looper with different threads -

visual studio 2010 - Connect to informix database windows form application -