The offset origin is not the top left corner?

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
kfitfk
Posts: 9
Joined: 2015-07-02T00:42:48-07:00
Authentication code: 6789

The offset origin is not the top left corner?

Post 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?
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

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

Post by Bonzo »

Does it help if you add +repage before the crop?
kfitfk
Posts: 9
Joined: 2015-07-02T00:42:48-07:00
Authentication code: 6789

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

Post 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.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

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

Post 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
kfitfk
Posts: 9
Joined: 2015-07-02T00:42:48-07:00
Authentication code: 6789

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

Post 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?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

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

Post 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.
Post Reply