Forum How do I...?

finding picture dimensions

jim_albright
Is there any way of finding out the dimensions of a picture from the CSS or XSLT?

The problem is that I have a user who wants to specify the approximate image size as width="10cm" but I need to make the height a multiple of the line height. Keeping the aspect ratio the same.

In the worst case I can view each graphic and build a file containing x, y, and resolution.

Jim Albright
Wycliffe Bible Translators

mikeday
It is not possible to access image dimensions from standard CSS or XSLT. Image tools like jpeginfo can be run from the command-line to determine this, and these could be used to generate an XML document mapping image filenames to dimensions that could then be accessed through XSLT. Alternatively, some XSLT processors allow extensions written in other languages, such as Java, which could do the job.
jim_albright
I used the following VB.NET class to help solve my problem. Sure is nice when people share their code. Saves us all time. ;)


<summary>
''' The ImageLoader class can retrieve image metadata using very little memory.
''' </summary>
''' <remarks>After constructing an ImageLoader, the object will expose
''' properties including file type, height, width, bits per pixel, etc.
''' The caller should first check that Type is not equal xNone
''' to confirm the object was constructed successfully.
'''
''' There are two methods that add more functionality: LoadBitmap and UnloadBitmap.
''' These control when and how the Bitmap property is loaded into memory.
'''
''' Submitted by Robert Chapin
''' Chapin Information Services, Inc. http://www.info-svc.com/
''' 24 January 2008
'''
''' This class is based on and inspired by David Crowell's code from
''' http://www.freevbcode.com/ShowCode.Asp?ID=112
''' Parts that were obviously buggy or not working in Mr Crowell's version
''' have been corrected. The rest of his algorithm is essentially unchanged.
'''
''' This class is being published in like kind at http://www.freevbcode.com
''' It is also being used in the latest beta version of ThetaWall at
''' http://www.info-svc.com/software/thetawall/

Jim Albright
Wycliffe Bible Translators

jim_albright
Glad to help out. I now have a GUI wrapper around Prince called Princess that computes the correct width and height of the inserted image and also adds padding to make sure the lines stay in register.

Jim Albright
Wycliffe Bible Translators