Page 1 of 2
Determine Total Canvas Size WITH Transparent Margins?
Posted: 2011-02-25T16:58:50-07:00
by dfelder
I have a png file with a 1000 x 1000 canvas and a transparent background. Centered within this canvas I have a 500 x 500 black square.
In other words, there are 250 pixels of transparent margin on each side of the square.
What command do I use to get the full canvas size (1000 x 1000)?
If I use identify, it will crop/trim the image and report back 500x500+250+250. That essentially ignores the blank space to the right and bottom. I want to determine the full size of the canvas--including transparency--regardless of its contents.
Thanks.
Re: Determine Total Canvas Size WITH Transparent Margins?
Posted: 2011-02-25T17:04:14-07:00
by anthony
You want the virtual canvas. identify reports both by default...
For example...
paged.gif GIF 46x46 64x64+9+9 8-bit PseudoClass 256c 3.09KB 0.000u 0:00.000
This is a 46x46 actual image, on a larger 64x64 virtual canavs with a +9+9 offset
Re: Determine Total Canvas Size WITH Transparent Margins?
Posted: 2011-02-25T17:17:36-07:00
by dfelder
Not exactly, no. The virtual canvas reports:
500x500 (the dimensions of the square) and +250+250 (the X/Y offset relative to the upper-left-hand pixel). I want to know that there are pixels to the right and bottom of my square.
With identify, it's essentially ignoring the fact that there are 250 more transparent pixels to the right and 250 more transparent pixels to the bottom of my square. For all intents and purposes, it's telling me my canvas is 750 x 750.
Re: Determine Total Canvas Size WITH Transparent Margins?
Posted: 2011-02-25T17:25:54-07:00
by anthony
Is this a PNG?
BY default PNG images does not save virtual canvas size information, just its offset. As such IM has to make a guess.
PNG images saved by IM however does include a extra meta-data tag that only IM understands that does include the virtual canavs size of images. But this is not a standard file format meta-data.
As such from PNG images coming from another source that information is not available.
Re: Determine Total Canvas Size WITH Transparent Margins?
Posted: 2011-02-25T17:47:49-07:00
by dfelder
It's a PNG or a PSD. If I open either file type in PhotoShop or Microsoft Picture Manager, both programs "know" to center the image on the screen within the canvas, and both programs reveal the transparent margin all around the image. In addition, one can view the "total" dimensions in Windows Explorer's expanded attributes. It's just difficult to extract them through the Shell.
It may not be standard, but in our business world (printing) it definitely is. We print everything centered along a centerline. Without knowing there are extra pixels off to the right, we'd never position it correctly.
Take for example two square images:
Image one: 400 x 400 (transparent) with a 200 x 400 (solid rectangle) LEFT justified
Image two: 400 x 400 (transparent) with a 200 x 400 (solid rectangle) RIGHT justified
If I print one on top of the other, I want the following results:
XX00
XX00
00XX
00XX
If I centered along the line and used 1/2 of the IM calculated width, I'd get:
_XX
_XX
00XX
00XX
Make sense?
Re: Determine Total Canvas Size WITH Transparent Margins?
Posted: 2011-02-26T08:50:29-07:00
by glennrp
If the image was created by ImageMagick in PNG format, then by
default the virtual canvas dimensions are stored in the vpAg chunk
which is a private ImageMagick chunk.
The pngtest.c program that comes with libpng demonstrates
how to read it into your own application, using libpng's user-chunk
feature.
Within ImageMagick, the virtual canvas is stored as page.width
and page.height .
I believe you can use the -flatten option to expand the image
to include the canvas; the surrounding pixels will be written
in the background_color:
Code: Select all
convert image_with_vpAg.png -flatten image_with_canvas.png
Sorry I can't test this right now, I'm writing from a public library
computer.
../glennrp
Re: Determine Total Canvas Size WITH Transparent Margins?
Posted: 2011-02-26T14:20:56-07:00
by dfelder
Unfortunately, these files are NOT created in IM. They are typically created in PhotoShop or GIMP. They are "client" files and I need to measure them. They definitely have blank margin to the right and bottom, and I am happy to share with you an example so you can see my conundrum.
Also, if I flatten them, then it ruins the original art. I'd have to first make a copy. If I flatten, the identify works without issue. The problem is, sometimes these files can be 5-50MB, so copying them is too inefficient.
As I mentioned earlier, it's an extended attribute that the Window Explorer Shell can see and display within the Windows folder view, so it's definitely there.
Thanks for the ideas.
Re: Determine Total Canvas Size WITH Transparent Margins?
Posted: 2011-02-26T20:57:54-07:00
by anthony
Photoshop presumably has its own 'special' chunk or meta-data, that defines a 'virtual canvas'. As such only photoshop knows about this information as it is specific to that application.
Re: Determine Total Canvas Size WITH Transparent Margins?
Posted: 2011-02-26T22:26:45-07:00
by dfelder
Actually, that's only partially correct. Photoshop knows it's there but so do all the microsoft apps. The images center properly in Microsoft photo editor and MS photo manager. It's definitely not a secret code. Like I have mentioned several times, even Windows explorer knows the full canvas size.
When I mention Windows explorer, I'm talking about the Windows directory. When you look at the image in the directory, by default it shows file type, date created, etc. If you right click in the top bar you can also view extended attributes such as DPI, date modified, AND diimensions.
This is standard since Windows Vista and the dimensions attribute reflects the entire canvas.
Re: Determine Total Canvas Size WITH Transparent Margins?
Posted: 2011-02-28T13:46:34-07:00
by dfelder
By the way, if there's a way to upload an image, I can provide screen shots.
Re: Determine Total Canvas Size WITH Transparent Margins?
Posted: 2011-02-28T13:59:59-07:00
by Tagomago
If you can upload it elsewhere online, use the tag to put it in the post.
Re: Determine Total Canvas Size WITH Transparent Margins?
Posted: 2011-03-01T13:31:14-07:00
by dfelder
I did a pretty extensive round of testing (results below), and you can see the deficiency for the PSD files (it looks like it's OK for the PNGs). It seems that the PixelXDimension and PixelYDimension variables (from identify -verbose) contains the required data for PSD files. The dimension data is at the very bottom of my results.
Is there a way to directly extract those two specific values using IM? In other words, can I directly obtain:
X = PixelXDimension
Y = PixelYDimension
without having extract it from the long analysis resulting from the verbose command?
<analysis results>
solid_400_400.psd
IM IDENTIFY:
Image: solid_400_400.psd
Format: PSD (Adobe Photoshop bitmap)
Geometry: 400x400+0+0
Page geometry: 400x400+0+0
______________________________________
solid_400_400.png
IM IDENTIFY:
Image: solid_400_400.png
Format: PNG (Portable Network Graphics)
Geometry: 400x400+0+0
Page geometry: 400x400+0+0
______________________________________
solid_200_400_right_justified_inside_400_400.psd
IM IDENTIFY:
Image: solid_200_400_right_justified_inside_400_400.psd
Format: PSD (Adobe Photoshop bitmap)
Geometry: 200x400+0+0
Page geometry: 200x400+200+0
Origin geometry: +200+0
______________________________________
solid_200_400_right_justified_inside_400_400.png
IM IDENTIFY:
Image: solid_200_400_right_justified_inside_400_400.png
Format: PNG (Portable Network Graphics)
Geometry: 400x400+0+0
Page geometry: 400x400+0+0
______________________________________
solid_200_400_left_justified_inside_400_400.psd
IM IDENTIFY:
Image: solid_200_400_left_justified_inside_400_400.psd
Format: PSD (Adobe Photoshop bitmap)
Geometry: 200x400+0+0
Page geometry: 200x400+0+0
______________________________________
solid_200_400_left_justified_inside_400_400.png
IM IDENTIFY:
Image: solid_200_400_left_justified_inside_400_400.png
Format: PNG (Portable Network Graphics)
Geometry: 400x400+0+0
Page geometry: 400x400+0+0
______________________________________
solid_200_400_left_justified_inside_400_400_WINDOWS_PHOTO_VIEWER.png
IM IDENTIFY:
Image: solid_200_400_left_justified_inside_400_400_WINDOWS_PHOTO_VIEWER.png
Format: PNG (Portable Network Graphics)
Geometry: 400x400+0+0
Page geometry: 400x400+0+0
______________________________________
solid_200_200_centered_inside_400_400.psd
IM IDENTIFY:
Image: solid_200_200_centered_inside_400_400.psd
Format: PSD (Adobe Photoshop bitmap)
Geometry: 200x200+0+0
Page geometry: 200x200+100+100
Origin geometry: +100+100
______________________________________
solid_200_200_centered_inside_400_400.png
IM IDENTIFY:
Image: solid_200_200_centered_inside_400_400.png
Format: PNG (Portable Network Graphics)
Geometry: 400x400+0+0
Page geometry: 400x400+0+0
______________________________________
solid_200_200_centered_inside_400_400_WINDOWS_PHOTO_VIEWER.png
IM IDENTIFY:
Image: solid_200_200_centered_inside_400_400_WINDOWS_PHOTO_VIEWER.png
Format: PNG (Portable Network Graphics)
Geometry: 400x400+0+0
Page geometry: 400x400+0+0
***************************
Image: offset.psd
Format: PSD (Adobe Photoshop bitmap)
Class: DirectClass
Geometry: 200x200+0+0
Page geometry: 200x200+165+166
Origin geometry: +165+166
exif:PixelXDimension: 400
exif:PixelYDimension: 400
Re: Determine Total Canvas Size WITH Transparent Margins?
Posted: 2011-03-01T14:49:04-07:00
by fmw42
Have you tried exiftool on your (PSD) images?
see
http://www.sno.phy.queensu.ca/~phil/exiftool/
Also see string formats in IM to get individual values --- http://www.imagemagick.org/script/escape.php
Re: Determine Total Canvas Size WITH Transparent Margins?
Posted: 2011-03-01T17:14:34-07:00
by anthony
You can upload images to the web using something like 'dropbox.com' You con't actually need the client, as you can upload them just using the web interface.
Re: Determine Total Canvas Size WITH Transparent Margins?
Posted: 2011-03-02T10:55:01-07:00
by dfelder
EXIFTOOL.exe reads them with "PixelXDimension" and "PixelYDimension" without issue. It's also clear that IM can read the dimensions I need in the PSD. They are identified in IM as:
exif:PixelXDimension: 400
exif:PixelYDimension: 400
Is there a way to obtain these values in IM without the -verbose method?
I'm scripting this so I need to extract:
XWidth = 000
YWidth = 000