Page 1 of 1

Crop and Repage with MPC Behaves Differently Than With PNG

Posted: 2015-07-24T00:42:07-07:00
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.

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

Posted: 2015-07-24T07:06:36-07:00
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.)

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

Posted: 2015-08-01T00:17:52-07:00
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.