Developer forum

Forum » Feature requests » Get the width and height of an image in the items tags

Get the width and height of an image in the items tags

Thomas Wiken
Reply

Hi, it would be great if the system could be set up to show the height and width of the image used in an file field in an item.

AMP pages requieres the width and height for an image to draw it correctly on the page. These values already exists in the filemanager.

Best regards
Thomas


Replies

 
Nicolai Pedersen
Reply

Hi Thomas

In your Razor template you can call Dynamicweb.Image.GetDimensions(path) (Returns System.Drawing.Point) and then you have your image dimensions.

BR Nicolai

 
Morten Lund
Morten Lund
Reply

Hi Nicolai

I have just tried what you suggested, but I get the error:

The type or namespace name 'Image' does not exist in the namespace 'Dynamicweb'

My code is:

        var imageFile  = GetString("Item.xxxx.ImageFile");
        var imagePath  = System.Web.HttpContext.Current.Server.MapPath(imageFile);
        var dimensions = Dynamicweb.Image.GetDimensions(imagePath);

​I have done it before, but not in DW9. I know a lot have changed but I cant figure out where to look for the answer ;)

 
Morten Lund
Morten Lund
Reply
This post has been marked as an answer

...and then I found it!

http://doc.dynamicweb.com/Default.aspx?ID=8258#article=a6afe4cd-6767-ebe7-8c3d-89f7ca8483ca

var dimensions = Dynamicweb.Image.GetDimensions(imagePath);

Should be:

var dimensions = Dynamicweb.Imaging.Image.GetDimensions(imagePath);
Votes for this answer: 1