Search code examples
imagemagick

imagemagick trim but keep canvas size and *position*


Friends,

I need to -trim some images but keep the original canvas size. Works like this:

convert in.png -fuzz 10% -trim -background white -set page "%[fx:w]x%[fx:h]" +repage out.png

But how can I position the trimmed image part at it's original position? -gravitiy center is not an option as the to-be-trimmed part usually not at the canvas center.

Any ideas?


Solution

  • You should be able to -trim an image, then use -flatten to lay it back onto its original canvas. Try this command...

    convert logo: -background none -trim -flatten trimmed.png