Page 2 of 2

Re: Determine Total Canvas Size WITH Transparent Margins?

Posted: 2011-03-02T14:05:47-07:00
by fmw42
see http://www.imagemagick.org/script/escape.php

convert image -format "%[exif:...]" info:`

Re: Determine Total Canvas Size WITH Transparent Margins?

Posted: 2011-03-02T18:19:25-07:00
by anthony
In that case you should be able to reset the virtual canvas to those dimensions using

Code: Select all

   -set page '%[exif:PixelXDimension]x%[exif:PixelYDimension]+%X+%Y'
after reading in the image.

That assumes the PNG virtual offset was also set correctly. It may be that the offsets should also come from EXIF tags as well. As some formats like JPEG does not even provide the normal virtual canvas 'offset', I would think offsets also are available in the EXIF tag. Perhaps a special -repage EXIF type operation can be added as a shortcut.

NOTE: I have not tested the above as I do not have an example image, and you have not provided a link to one

I do not know if IM can change those settings before writing. If currently can modify 'exif:Orientation'!
http://www.imagemagick.org/Usage/photos/#orient
But should IM do read/write this setting, if such a EXIF tag exists in an image?
This is something that may need some debate by users.
I think it would be a 'cool' addition and could possibly be used to replace the existing 'special IM meta-data' it provides for PNG images.

WARNING: Adding virtual canvas settings can effect many IM image processing methods, such as distortions, cropping, and even resize. Removing virtual canvas settings is however easy using +repage

Re: Determine Total Canvas Size WITH Transparent Margins?

Posted: 2011-03-03T18:21:57-07:00
by dfelder
First off, I really appreciate the help here. You can see I only joined this forum for this question. I do actively provide help on several other boards (if it makes you feel better!), so again, thanks...

Second, I have posted a series of files here: http://garmentdeli.com/IM/
At the end of the day, I need to extract true total canvas X & Y, and DPI (NOT DP-Centimeter!) from PNGs and PSDs similar to these samples. Any help would be greatly appreciated.

BTW, I'm working under the assumption IM won't work so I keep experiementing with Shell code, and EXIF extractors. I'm holding out for IM, though, because I already got my application to integrate with it.

Re: Determine Total Canvas Size WITH Transparent Margins?

Posted: 2011-03-05T16:31:00-07:00
by Drarakel
Well, you first wrote a lot about PNG and that getting the canvas works with e.g. Windows Explorer, but not with ImageMagick. When there's obviously no problem at all with PNGs. That makes helping a bit difficult..


Anyway.. Your PNGs don't even have an offset - so getting the canvas is of course easy there.
With PSDs, it normally should work, too. But there seems to be a bug with some of these files within the current IM. (I'll write a bug report.)
Till there's a fix for that, you could theoretically use that workaround with the dimensions in the EXIF profile. But I wouldn't recommend that at all. There doesn't have to be such a profile in PSD files. And even if there is, the information doesn't have to be correct (it could be the information from an older version of the image). It's just metadata which has no influence on the image itself.

So.. right now you can either go back to an older ImageMagick version - where this type of PSD files still works. Or use e.g. ExifTool to get the right properties from the (Photoshop) header (not from the EXIF tags!):

Code: Select all

exiftool -S -s -ImageSize file.psd
(Or use the separate tags "-Photoshop:ImageWidth" and "-Photoshop:ImageHeight" instead.)

dfelder wrote:I need to extract ... DPI (NOT DP-Centimeter!) from PNGs and PSDs
You can do that with ImageMagick like that, for example:

Code: Select all

identify -units PixelsPerInch -format "%x\n%y" file
That should work ok - at least for PNGs. Note that the information for the density values and the unit can be stored in a lot of different places/profiles. If you have differing (outdated) values stored at these places, you'll get into trouble with ImageMagick. And with PSD, it's especially risky. (Here, IM takes the density from the Photoshop profile, but the unit from the XMP profile. And if there's no XMP profile, the unit in IM is 'undefined' at first. It seems that the unit in the Photoshop profile doesn't get read by IM.)
The other possibility is again with e.g. ExifTool. There, you could specifically read only the info from the Photoshop profile (with PSDs), or from the pHYs chunk (with PNGs). But then, if you have a value in PixelsPerCentimeter, you'll get no automatic conversion to PixelsPerInch, of course.

Re: Determine Total Canvas Size WITH Transparent Margins?

Posted: 2011-03-07T11:08:16-07:00
by dfelder
Thanks for the suggestion. I have been concurrently working with EXIFTOOL, but have had a difficult time incorporating it into VBA. I have IM working, so it's much preferred.

Can you confirm that this DID work with previous versions of IM? Before I go through a re-install and testing, I'd like to make sure I'm using a version that works.

Thanks.

Re: Determine Total Canvas Size WITH Transparent Margins?

Posted: 2011-03-07T13:19:54-07:00
by Drarakel
dfelder wrote:Can you confirm that this DID work with previous versions of IM?
Yes. See some details in the bug report.

But I think, you don't need to go back to an older IM version now - as the fix for that problem has already been incorporated into the new version 6.6.8-1. (Can't test it though, as at least the current Q16 Win32 binary is still version 6.6.8-0.)
So, with that new version, you should be able to get the size again with just:

Code: Select all

identify -format "%Wx%H" file.psd

Re: Determine Total Canvas Size WITH Transparent Margins?

Posted: 2011-03-07T13:54:17-07:00
by dfelder
I am replying only because we are both actively look at this today. Is this the 6.8.8-1 to which you are referring:

http://www.imagemagick.org/script/binar ... hp#windows

I actually think it was just released.

Re: Determine Total Canvas Size WITH Transparent Margins?

Posted: 2011-03-07T14:21:43-07:00
by dfelder
I just tried the version with 6.6.8-1 in the release, but:

1) it installed as "6.6.8-0"
2) it still doesn't work

Just thought I'd pass this along.

What I'm expecting to see is this:

identify -format %Wx%H offset.png
400x400

identify -format %Wx%H offset.psd
400x400

Is my assumption correct? (These are the files downloaded from my link above.)

Re: Determine Total Canvas Size WITH Transparent Margins?

Posted: 2011-03-07T15:05:19-07:00
by Drarakel
dfelder wrote:Is my assumption correct?
Yes. See also:
Drarakel wrote:at least the current Q16 Win32 binary is still version 6.6.8-0.
Just wait a few more days. Or ask at the 'Bugs' board if the Windows binaries can be updated.

Re: Determine Total Canvas Size WITH Transparent Margins?

Posted: 2011-03-07T17:30:59-07:00
by glennrp
dfelder wrote: Second, I have posted a series of files here: http://garmentdeli.com/IM/
There's no offset or canvas information in those PNG files. The IHDR
chunk contains only the canvas dimensions, not the dimensions of
the overlaid image.

Re: Determine Total Canvas Size WITH Transparent Margins?

Posted: 2011-03-09T21:30:34-07:00
by Drarakel
dfelder wrote:What I'm expecting to see is this:
...
identify -format %Wx%H offset.psd
400x400
FYI: It now works with IM v6.6.8-2. The windows binaries have been updated:
http://www.imagemagick.org/script/binar ... hp#windows

Note that with PSDs, you now have to add the layer number 0 (for the composite layer; otherwise you'll get the sizes for all the layers). So, it's now:

Code: Select all

identify -format "%Wx%H" file.psd[0]

Re: Determine Total Canvas Size WITH Transparent Margins?

Posted: 2011-03-10T10:55:22-07:00
by dfelder
Thanks for your help on this. As it turns out, the [0] actually works with the old version, as well. :D

Best to all!

Re: Determine Total Canvas Size WITH Transparent Margins?

Posted: 2011-03-10T12:31:04-07:00
by Drarakel
dfelder wrote:As it turns out, the [0] actually works with the old version, as well.
I see.. Interesting. :) (But still, the old versions had a bug there.)