Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Jason Espin 368 posts 1335 karma points
    Apr 11, 2014 @ 12:30
    Jason Espin
    0

    Accessing the Width and Height attributes of images uploaded with Multiple Media Picker

    I wish to know how to access the width and height attributes of images uploaded using the Multiple Media Picker. The images that are being uploaded are going to be used as part of a Carousel but to ensure that the look and feel of this element does not break through the use of different sized images I am going to ensure that images that do not match the width and height requirements of the Carousel are not output as part of the collection.

    I'm currently doing the following:

    var bannerImagesList = Model.Content.GetPropertyValue<string>("bannerImages").Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries).Select(int.Parse);
    
    var bannerImagesCollection = Umbraco.TypedMedia(bannerImagesList).Where(x => x != null);
    

    I then have a foreach loop where I output each image:

     @foreach (var bannerImage in bannerImagesCollection){
                var cssClass = imageCount < 1 ? "item active" : "item";
    
                <div class="@cssClass">
                    <img src="@bannerImage.Url" alt="@bannerImage.Id" />
                </div>
                imageCount++;
            }
    

    I can access the ID of the image just fine using @bannerImage.Id as this is a property but how to I gain access to the attribute s of the image itself and not the properties of the object?

  • Jeavon Leopold 3074 posts 13632 karma points MVP 11x admin c-trib
    Apr 11, 2014 @ 12:39
    Jeavon Leopold
    100

    Hi Jason,

    Are you using the standard "Image" media type or one of your own?

    If you are using the standard "Image" media type, you can do this:

    <img src="@bannerImage.Url" style="width: @bannerImage.GetPropertyValue("umbracoWidth")px; height: @bannerImage.GetPropertyValue("umbracoHeight")px" />
    

    Jeavon

  • Jason Espin 368 posts 1335 karma points
    Apr 11, 2014 @ 13:11
    Jason Espin
    0

    Hi Jeavon,

    I am using the standard Image media type as I have not declared any of my own Media Types. How would I then go about checking to see if my image widths match what I need? I've tried the following:

    if(@bannerImage.GetPropertyValue("UmbracoWidth") == 1200 )
    

    But in VisualStudio is states that the == operator cannot be used on types 'int' or 'Object'.

    Jason

  • Jason Espin 368 posts 1335 karma points
    Apr 11, 2014 @ 13:59
    Jason Espin
    1

    Nevermind. I think I've sussed it now.

    if (@bannerImage.GetPropertyValue<int>("umbracoWidth") >2000){
    ...
    }
    
  • Jeavon Leopold 3074 posts 13632 karma points MVP 11x admin c-trib
    Apr 11, 2014 @ 14:04
    Jeavon Leopold
    0

    That's the one :-)

Please Sign in or register to post replies

Write your reply to:

Draft