trim does not remove the black border from JPEG

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
wizzofoz

trim does not remove the black border from JPEG

Post by wizzofoz »

I've done some testing with the -trim option with self created files (Fireworks) and it seemed to work ok but when I try to trim my scanned images the border does not disappear.

I use (from the windows command prompt) the following command:

convert -trim input.jpg output.jpg

Please ask me for an example file if you want to test it
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: trim does not remove the black border from JPEG

Post by Bonzo »

I have never used trim but try adding +repage

Code: Select all

convert input.jpg -trim +repage output.jpg
el_supremo
Posts: 1015
Joined: 2005-03-21T21:16:57-07:00

Re: trim does not remove the black border from JPEG

Post by el_supremo »

A scanned image probably doesn't have a border with a pure colour. Add -fuzz 20 to your command and see how much it trims off. Then play with the fuzz value to get the right amount trimmed off.
See: http://imagemagick.org/script/command-l ... s.php#fuzz

Pete
wizzofoz

Re: trim does not remove the black border from JPEG

Post by wizzofoz »

Sorry to tell that both of your solutions do not work.

If you want to test is yourself, please tell me where to send some test images ...
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: trim does not remove the black border from JPEG

Post by anthony »

+repage does not work for JPEG, as this file format does not use virtual canvas information. PNG does but only partially, GIF definably does.

The problem is JPG is lossy. Colors are not EXACTLY as you thing they are.

As such to trim you need to tell IM to allow 'near' colors too. To do this add a 'fuzz factor.

Code: Select all

     -fuzz 1% -trim
See IM Examples, Fuzz Factor...
http://www.imagemagick.org/Usage/color/#fuzz
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply