Page 1 of 1

The offset origin is not the top left corner?

Posted: 2015-07-15T02:18:41-07:00
by kfitfk
I have a PSD document which contains an image as shown below

Image

The PSD canvas size is 425x320, and the image in the layer itself is 714x329. If the top left corner of the PSD canvas is (0, 0), then the top left corner of the layer should be (-49, -3).

I exported the layer using the following command:

Code: Select all

convert demo.psd[2] output.png
And here is the exported image.

Image

Then I use the following command to crop it:

Code: Select all

convert output.png -crop 425x320+49+3\! cropped.png
And here is the cropped image. Notice that it is not the same area as shown in the PSD canvas.

Image

It turns out that when cropping, the offset origin of output.png is not the top left corner corner. It is the point that matches the (0, 0) point of the PSD canvas. So if I do

Code: Select all

convert output.png -crop 425x320+0+0\! cropped.png
I can then get the image just like I do a "save as png" command in Photoshop.

My question is why the default offset origin of output.png is not the top left corner? Does this has something to do with my convert command? If I get an image from a third party, how do I check the default crop origin?

Re: The offset origin is not the top left corner?

Posted: 2015-07-15T02:38:12-07:00
by Bonzo
Does it help if you add +repage before the crop?

Re: The offset origin is not the top left corner?

Posted: 2015-07-15T03:01:07-07:00
by kfitfk
Bonzo wrote:Does it help if you add +repage before the crop?

Code: Select all

convert output.png +repage -crop 425x320+0+0\! cropped.png
Yes, this works. Just checked out the documentation. This operator completely removes/resets the virtual canvas meta-data from the images.

I have another issue then. What if in this case output.png itself is smaller than my desired crop size? I still want to keep the result image 425x320.

Thanks.

Re: The offset origin is not the top left corner?

Posted: 2015-07-15T09:33:06-07:00
by fmw42
then you need to pad. try

Code: Select all

convert output.png +repage -crop 425x320+0+0\! +repage -gravity center -background black -extent 425x320 cropped.png
see http://www.imagemagick.org/Usage/crop/#extent

Re: The offset origin is not the top left corner?

Posted: 2015-07-15T23:33:38-07:00
by kfitfk
Thanks, fmw42. -extent works great.

Does the viewport cropping method described in this section http://www.imagemagick.org/Usage/crop/#crop_viewport only applies to gif output?

Re: The offset origin is not the top left corner?

Posted: 2015-07-16T08:45:50-07:00
by fmw42
kfitfk wrote:Thanks, fmw42. -extent works great.

Does the viewport cropping method described in this section http://www.imagemagick.org/Usage/crop/#crop_viewport only applies to gif output?
No. Any format that saves the virtual canvas information. That would include GIF and PNG. I am not sure about TIFF. But does not include JPG.