Determine Total Canvas Size WITH Transparent Margins?
- anthony
- Posts: 8883
- Joined: 2004-05-31T19:27:03-07:00
- Authentication code: 8675308
- Location: Brisbane, Australia
Re: Determine Total Canvas Size WITH Transparent Margins?
In that case you should be able to reset the virtual canvas to those dimensions using
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
Code: Select all
-set page '%[exif:PixelXDimension]x%[exif:PixelYDimension]+%X+%Y'
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
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
https://imagemagick.org/Usage/
Re: Determine Total Canvas Size WITH Transparent Margins?
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.
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?
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!):(Or use the separate tags "-Photoshop:ImageWidth" and "-Photoshop:ImageHeight" instead.)
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.
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
You can do that with ImageMagick like that, for example:dfelder wrote:I need to extract ... DPI (NOT DP-Centimeter!) from PNGs and PSDs
Code: Select all
identify -units PixelsPerInch -format "%x\n%y" file
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?
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.
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?
Yes. See some details in the bug report.dfelder wrote:Can you confirm that this DID work with previous versions of IM?
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?
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.
http://www.imagemagick.org/script/binar ... hp#windows
I actually think it was just released.
Re: Determine Total Canvas Size WITH Transparent Margins?
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.)
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?
Yes. See also:dfelder wrote:Is my assumption correct?
Just wait a few more days. Or ask at the 'Bugs' board if the Windows binaries can be updated.Drarakel wrote:at least the current Q16 Win32 binary is still version 6.6.8-0.
Re: Determine Total Canvas Size WITH Transparent Margins?
There's no offset or canvas information in those PNG files. The IHDRdfelder wrote: Second, I have posted a series of files here: http://garmentdeli.com/IM/
chunk contains only the canvas dimensions, not the dimensions of
the overlaid image.
Re: Determine Total Canvas Size WITH Transparent Margins?
FYI: It now works with IM v6.6.8-2. The windows binaries have been updated:dfelder wrote:What I'm expecting to see is this:
...
identify -format %Wx%H offset.psd
400x400
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?
Thanks for your help on this. As it turns out, the [0] actually works with the old version, as well.
Best to all!
Best to all!
Re: Determine Total Canvas Size WITH Transparent Margins?
I see.. Interesting. (But still, the old versions had a bug there.)dfelder wrote:As it turns out, the [0] actually works with the old version, as well.