Crop and Repage with MPC Behaves Differently Than With PNG

Post any defects you find in the released or beta versions of the ImageMagick software here. Include the ImageMagick version, OS, and any command-line required to reproduce the problem. Got a patch for a bug? Post it here.
Post Reply
zian
Posts: 2
Joined: 2015-07-24T00:37:44-07:00
Authentication code: 1151
Contact:

Crop and Repage with MPC Behaves Differently Than With PNG

Post by zian »

Running the crop and repage commands result in different input if the image file is a MPC or PNG derived from the MPC.

Version: ImageMagick 6.9.1-Q16
Operating System: Windows 7 x64
Processor: Intel(R) Core(TM) i5-3570K CPU @ 3.40 GHz
Installed memory (RAM): 8.00 GB

Command line:
Given the MPC and Cache files available at OneDrive: http://1drv.ms/1DATSjd

1. convert "iCopy 2015-07-23 11-16 000_1.mpc" -virtual-pixel edge -blur 0x15 -fuzz 10% -trim -format "%wx%h%O" info:
2. You will see "1875x3484+1350+567"
3. convert "iCopy 2015-07-23 11-16 000_1.mpc" "iCopy 2015-07-23 11-16 000_1.png"
4. convert "iCopy 2015-07-23 11-16 000_1.png" -virtual-pixel edge -blur 0x15 -fuzz 10% -trim -format "%wx%h%O" info:
5. You will see "1875x3484+1350+567" again
6. Run the following commands to crop the images and get rid of the gray
convert "iCopy 2015-07-23 11-16 000_1.mpc" -monitor -crop "1875x3484+1350+567" +repage "bad.png"
convert "iCopy 2015-07-23 11-16 000_1.png" -monitor -crop "1875x3484+1350+567" +repage "good.png"
7. Notice that bad.png shows a tiny sliver of the receipt whereas good.png shows the entire receipt.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Crop and Repage with MPC Behaves Differently Than With PNG

Post by snibgo »

The input MPC contains an offset of -5-1, which you probably don't want. "+repage" will get rid of it. But that's not the real problem.

The real problem is that the input MPC contains a gravity setting. This isn't copied to the PNG because PNG can't contain gravity metadata. Override this with an explicit gravity in your final command:

Code: Select all

convert "iCopy 2015-07-23 11-16 000_1.mpc" -gravity NorthWest -crop "1875x3484+1350+567" +repage "better.png"

convert "iCopy 2015-07-23 11-16 000_1.png" -gravity NorthWest  -crop "1875x3484+1350+567" +repage "good.png"
(I've also added it to the PNG command, where it is superfluous but harmless.)
snibgo's IM pages: im.snibgo.com
zian
Posts: 2
Joined: 2015-07-24T00:37:44-07:00
Authentication code: 1151
Contact:

Re: Crop and Repage with MPC Behaves Differently Than With PNG

Post by zian »

I adapted your suggestions to reset the coordinate system and explicitly set the gravity. The changes fixed the problem.

Thank you for the help.
Post Reply