Remove white background and resize

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
mikeinpdx

Remove white background and resize

Post by mikeinpdx »

I'm fairly new to ImageMagick, but have used some of the command line tool/options to do basic stuff.

I've got a lot of images that have varying amounts of white background (photos of commercial products). I'd like to make the image sizes consistent, which probably isn't too hard. But ideally what I would like to do is remove the white background, then resize the image so that the image is enlarged as much as possible to fit within a given constraint and isn't affected by the background.

In other words, suppose the image is actually 25% white border/background. I'd like to resize that inner 75%, so that the scaled image has no boarder, making the processed image as large as possible given the size constraints, and not wasting image area on borders. Is that possible?
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: Remove white background and resize

Post by Bonzo »

Show an example image; -trim will remove a border.

This artical may be of interest: http://tech.natemurray.com/2007/12/conv ... arent.html
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Remove white background and resize

Post by fmw42 »

given you know your input size ahead of time:

use convert input -fuzz XX% -trim +repage -resize WIDTHxHEIGHT output

see http://www.imagemagick.org/script/comma ... p#geometry
mikeinpdx

Re: Remove white background and resize

Post by mikeinpdx »

Thanks! That's exactly what I needed.
Post Reply