#189 convert -trim fails on 8-bit PNG that ImageMagick can trim


Here is the gm identify on the original PNG:
foo.png PNG 640x480+0+0 DirectClass 8-bit 23.2K 0.000u 0:01

The resulting footrim.png from ImageMagick:
* successfully trimmed to 613x400 (from 640x480)

The following command fails to trim a PNG that can be trimmed using ImageMagick's "convert.exe -trim" command:
gm convert -trim foo.png footrim.png

The resulting footrim.png from GraphicsMagick:
1. has same dimension 640x480 as original
2. interestingly, it has smaller file size (16,535 bytes vs original 23,724 bytes)

NOTE: using -fuzz didn't make any difference (I tried up to 50%).

I'm using GraphicsMagick 1.3.14 2012-02-25 Q16 (pre-built binary download) on Windows 7 x64 with AMD Phenom processor.

I'm unable to share the PNG because I don't have permission to distribute it. It has a black rectangle frame 613x400 inside a 640x480 white background The black rectangle frame is at least 5 pixels thick. All four corners and the margin surrounding the rectangle are white.

I hope this bug is fixed, trim is the most important feature to us and I prefer GraphicsMagick's emphasis on performance and security...


  • Bob Friesenhahn

    Bob Friesenhahn - 2012-05-01

    Can you please post the full output of 'gm identify -verbose' for this PNG file? Are you able to find a similar file exhibiting the same bug that you are able to share?

  • Salvor Hardin

    Salvor Hardin - 2012-05-04

    Hi! Here's the 'gm -identify -verbose'. I will see if I can reproduce this with an image I can share. Thanks in advance for looking into this!

    Image: foo.png
    Format: PNG (Portable Network Graphics)
    Geometry: 640x480
    Class: DirectClass
    Type: true color
    Depth: 8 bits-per-pixel component
    Channel Depths:
    Red: 8 bits
    Green: 8 bits
    Blue: 8 bits
    Opacity: 1 bits
    Channel Statistics:
    Minimum: 0.00 (0.0000)
    Maximum: 65535.00 (1.0000)
    Mean: 60648.29 (0.9254)
    Standard Deviation: 17159.36 (0.2618)
    Minimum: 0.00 (0.0000)
    Maximum: 65535.00 (1.0000)
    Mean: 60648.29 (0.9254)
    Standard Deviation: 17159.36 (0.2618)
    Minimum: 0.00 (0.0000)
    Maximum: 65535.00 (1.0000)
    Mean: 61563.99 (0.9394)
    Standard Deviation: 14838.72 (0.2264)
    Minimum: 0.00 (0.0000)
    Maximum: 0.00 (0.0000)
    Mean: 0.00 (0.0000)
    Standard Deviation: 0.00 (0.0000)
    Rendering-Intent: saturation
    Gamma: 0.45455
    red primary: (0.64,0.33)
    green primary: (0.3,0.6)
    blue primary: (0.15,0.06)
    white point: (0.3127,0.329)
    Filesize: 23.2K
    Interlace: No
    Orientation: Unknown
    Background Color: white
    Border Color: #DFDFDF00
    Matte Color: #BDBDBD00
    Compose: Over
    Dispose: Undefined
    Iterations: 0
    Compression: Zip
    Signature: 87bf96a30ba5ff4d4e1b4815d706cf0d2e9a90aea3e5c2f0aa8eb6ac11bedd09
    Tainted: False
    User Time: 0.031u
    Elapsed Time: 0:01
    Pixels Per Second: 10.1M

  • Bob Friesenhahn

    Bob Friesenhahn - 2012-05-04

    As a guess, perhaps the problem has something to do with the image having a transparency channel (even though it seems totally opaque). Can you try doing

    gm convert foo.png +matte -trim footrim.png

    and see if the trim then succeeds?

  • Bob Friesenhahn

    Bob Friesenhahn - 2012-05-05

    This issue definitely has something to do with the opacity channel since I am able to reproduce it if I add an opacity channel to an image.

  • Bob Friesenhahn

    Bob Friesenhahn - 2012-05-05

    This problem is fixed by Mercurial changeset bcac6bd55ccb. The problem is that if the image was non-opaque, the opacity layer was used instead of the color layers in order to find the bounding box. The algorithm has now been changed so that the opacity layer is only used to find the bounding box if all three of the reference points are non-opaque and have the same value.

  • Bob Friesenhahn

    Bob Friesenhahn - 2012-05-05
    • status: open --> closed-fixed
  • Salvor Hardin

    Salvor Hardin - 2012-05-06

    Amazing, you already fixed it before I can reply with a sample image!

    I already have to work many hours today (Sunday) so this is very helpful.

    Thanks so much!!!


Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

JavaScript is required for this form.

No, thanks