convert and trim problem

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
bensto
Posts: 31
Joined: 2012-07-02T00:32:10-07:00
Authentication code: 13

convert and trim problem

Post by bensto »

I want to remove all white pixel border (!) lines inside a picture around the actual content.

For that I enter the following command:

convert.exe -trim D:\tmp\2.jpg and got the following error (under 64bit Win7):

convert.exe: no images defined `D:\tmp\2.jpg' @ error/convert.c/ConvertImageCommand/3085.

Hmm, the picture exists!. Whats wrong?

Other related question: Assume I dont want not only to remove/trim pure white color lines but also almost white lines.
Lets say I want to remove lines whose "whiteness" is maximum 3% different from "pure" white.

How can I achieve this?

Ben
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: convert and trim problem

Post by fmw42 »

Your syntax is in error. Properly, you should open the input image before trimming or most any other operation.

convert image -fuzz 3% -trim +repage output

see
http://www.imagemagick.org/Usage/crop/#trim

Note the +repage (to remove the virtual canvas) is not needed for jpg output, but could be needed for gif, png and tif
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: convert and trim problem

Post by snibgo »

To expand slightly on fmw's explanation: convert needs an input file and an output file. They can be the same name, but you must provide them both. So your command could be:

Code: Select all

convert D:\tmp\2.jpg -fuzz 3% -trim +repage D:\tmp\2.jpg
snibgo's IM pages: im.snibgo.com
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: convert and trim problem

Post by anthony »

UNLESS you use "mogrify" that reads processes and writes images to the same file name, but (currently) only allowing 'simple' image operations. Note that -trim is a simple image operation.

Code: Select all

mogrify -fuzz 3% -trim +repage D:\tmp\2.jpg
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply