Copied to clipboard

Flag this post as spam?

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


  • Tony Groome 261 posts 804 karma points
    Feb 13, 2015 @ 16:19
    Tony Groome
    0

    How to differenciate between landscape & portrait

    Hi All

    I have some photos on my site. When you click on one it appears on another page in a bigger size and with some text underneath. Fine. The problem is when a photo is in portrait mode it gets cropped as the bigger size is 450px by 338px. I have tried:

    <div class="column w470 gut10 centerAlign">

    @foreach(var page in CurrentPage.Children.Reverse().Take(5))

    {

    dynamic image=null;

    if (page.HasValue("image"))

    {                                         

                var dynamicMediaItem = Umbraco.Media(page.image);

    <div class="content-page-wide-box">

    <div class="column w220">

    if (@dynamicMediaItem.umbracoWidth >= @dynamicMediaItem.umbracoHeight){

                <img src="@dynamicMediaItem.GetCropUrl("foundation")" alt="@dynamicMediaItem.Name" style="padding:5px 5px 5px 5px"/>

    }

    else{

    <img src="@dynamicMediaItem.GetCropUrl("portrait")" alt="@dynamicMediaItem.Name" style="padding:5px 5px 5px 5px"/>

    }

    </div>

    Am I close? I'm getting the if statement filled in on the front end ie:

    if(100 >= 100){

    the rest is hidden by a button! 

    Thanks.

    Tony

  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    Feb 13, 2015 @ 16:23
  • Tony Groome 261 posts 804 karma points
    Feb 13, 2015 @ 16:42
    Tony Groome
    0

    Hi Dennis

    I'm using the image cropper - you gave me that link before and it got the cropper working. I just can't figure out how to see if the image is landscape or portrait. The idea being that if it is landscape - we get a large landscape image on the next page. If it is a portrait, then the large image is a portrait image. 

    I have just tried:

    @foreach(var page in CurrentPage.Children.Reverse().Take(5))

    {

    dynamic image=null;

    if (page.HasValue("image"))

    {                                         

                var dynamicMediaItem = Umbraco.Media(page.image);

    <div class="content-page-wide-box">

     

    int width = dynamicMediaItem.GetPropertyValue<int>("umbracoWidth");

               int height = dynamicMediaItem.GetPropertyValue<int>("umbracoHeight");

     

     

    if (width >= height)

    {

    <div class="column w220">

               <img src="@dynamicMediaItem.GetCropUrl("foundation")" alt="@dynamicMediaItem.Name" style="padding:5px 5px 5px 5px"/>

    </div>

    }

    else

    {

    <div class="column w220">

    <img src="@dynamicMediaItem.GetCropUrl("portrait")" alt="@dynamicMediaItem.Name" style="padding:5px 5px 5px 5px"/>

    </div>

    }

     

    <div class="column w220">

    <center><span style="line-height: 1.4em; padding:5px 5px 5px 5px;font-size: 16px; font-weight: bold;">@page.Name</span></center>

    </div>

    <div class="column w220">

    <span style="float:right; padding:10px 10px 10px 10px;">@page.summary</span>

    </div>

    <div class="column w470">

    <p><a class="buttonGrey block w160" target="_blank" [email protected] rel="nofollow">@page.Name<span class="arrow"></span></a></p>

               </div>

    </div>

    }

    }

    I tried instantiating the width and height variables as vars and ints and in both cases the line of code appears on the front end along with both images from the if else statements! Maybe it's just the 13th!!
    Thanks.
    Tony
  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Feb 13, 2015 @ 18:33
    Jan Skovgaard
    1

    Hi Tony

    You'll need to have a look at the height and width to figure out, which state the image is in.

    If the image height is greater than the width it's in portrait mode and if the image width is greater than the height it's landscape. That's all there should be to it I think :)

    Hope this makes sense.

    /Jan

  • Tony Groome 261 posts 804 karma points
    Feb 16, 2015 @ 11:03
    Tony Groome
    0

    Hi Jan

    That's the problem I can't get the code to work for grabbing the width and height! My if statement appears on the front end with both images! 

    Any ideas?

    Thanks.

    Tony

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Feb 16, 2015 @ 11:17
    Jan Skovgaard
    1

    Hi Tony

    Have you checked if the width and height variables get the correct values? What happens if you don't check for whether it's also equal to the height but just check if it's greater than the height?

    /Jan

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Feb 16, 2015 @ 11:19
    Jan Skovgaard
    1

    ..Actually you should probably just check if the height is greater than the width and then render the code for the portrait mode otherwise just render landscape. Then you just need to check if(height > width).

    /Jan

  • Tony Groome 261 posts 804 karma points
    Feb 16, 2015 @ 11:31
    Tony Groome
    0

    Hi Jan

    I tried this:

    if (page.HasValue("image"))

    {                                         

                <div class="content-page-wide-box">

     

    var dynamicMediaItem = Umbraco.TypedMedia(page.image);

    int width = dynamicMediaItem.GetPropertyValue<int>("umbracoWidth");

                int height = dynamicMediaItem.GetPropertyValue<int>("umbracoHeight");

     

     

     

    if (width < height)

    {

    <div class="column w220">

    <img src="@dynamicMediaItem.GetCropUrl("portrait")" alt="@dynamicMediaItem.Name" style="padding:5px 5px 5px 5px"/>

    </div>

    <div class="column w220">

    <center><span style="line-height: 1.4em; padding:5px 5px 5px 5px;font-size: 16px; font-weight: bold;">@page.Name</span></center>

    </div>

    <div class="column w220">

    <span style="float:right; padding:10px 10px 10px 10px;">@page.summary</span>

    </div>

    <div class="column w470">

    <p><a class="buttonGrey block w160" target="_blank" [email protected] rel="nofollow">@page.Name<span class="arrow"></span></a></p>

               </div>

    }

    else

    {

    <div class="column w220">

    <img src="@dynamicMediaItem.GetCropUrl("foundation")" alt="@dynamicMediaItem.Name" style="padding:5px 5px 5px 5px"/>

    </div>

    <div class="column w220">

    <center><span style="line-height: 1.4em; padding:5px 5px 5px 5px;font-size: 16px; font-weight: bold;">@page.Name</span></center>

    </div>

    <div class="column w220">

    <span style="float:right; padding:10px 10px 10px 10px;">@page.summary</span>

    </div>

    <div class="column w470">

    <p><a class="buttonGrey block w160" target="_blank" [email protected] rel="nofollow">@page.Name<span class="arrow"></span></a></p>

               </div>

     

    }

    But now the name 'dynamicMediaItem' does not exist in the current context. I thought the div might have been causing problems....

    I have two crop sizes set up in the cropper in data types, so the idea is if width < height produce the portrait crop or else produce the landscape crop. I was trying to use Jonas' code from here https://our.umbraco.org/forum/developers/razor/49409-Check-if-image-is-landscape-or-portrait but it doesn't like it. Maybe because my image is coming from a foreach loop....

    Thanks.

    Tony


  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Feb 16, 2015 @ 12:03
    Jan Skovgaard
    1

    Hi Tony

    I think it's perhaps a matter of placing the @ sign the proper places...but it's a bit hard to get the full code context from above since the default rich text editor in the forum does not do a good job about formatting it...so could you try to paste it into pastebin.com for instance or switch to using the mark down version of the editor in this forum?

    A simple approach for debugging the code is to simply comment out all the lines and then start checking the code line for line and see where and when it breaks and then figure out what is the trigger.

    /Jan

  • Tony Groome 261 posts 804 karma points
    Feb 16, 2015 @ 12:21
    Tony Groome
    0

    Hi Jan

    I sent the code to pastebin here http://pastebin.com/7n5gF20C Or else here:

    @foreach(var page in CurrentPage.Children.Reverse().Take(5)) { dynamic image=null; if (page.HasValue("image")) {

            var dynamicMediaItem = Umbraco.TypedMedia(page.image);
            int width = dynamicMediaItem.GetPropertyValue<int>("umbracoWidth");
            int height = dynamicMediaItem.GetPropertyValue<int>("umbracoHeight");
    
    
    
                if (width < height)
                {
                    <div class="column w220">
                        <img src="@dynamicMediaItem.GetCropUrl("portrait")" alt="@dynamicMediaItem.Name" style="padding:5px 5px 5px 5px"/>
                    </div>
                    <div class="column w220">
                        <center><span style="line-height: 1.4em; padding:5px 5px 5px 5px;font-size: 16px; font-weight: bold;">@page.Name</span></center>
                    </div>
                    <div class="column w220">
                        <span style="float:right; padding:10px 10px 10px 10px;">@page.summary</span>
                    </div>
                    <div class="column w470">
                        <p><a class="buttonGrey block w160" target="_blank" [email protected] rel="nofollow">@page.Name<span class="arrow"></span></a></p>
                    </div>
                }
                else
                {
                    <div class="column w220">
                        <img src="@dynamicMediaItem.GetCropUrl("foundation")" alt="@dynamicMediaItem.Name" style="padding:5px 5px 5px 5px"/>
                    </div>
                    <div class="column w220">
                        <center><span style="line-height: 1.4em; padding:5px 5px 5px 5px;font-size: 16px; font-weight: bold;">@page.Name</span></center>
                    </div>
                    <div class="column w220">
                        <span style="float:right; padding:10px 10px 10px 10px;">@page.summary</span>
                    </div>
                    <div class="column w470">
                        <p><a class="buttonGrey block w160" target="_blank" [email protected] rel="nofollow">@page.Name<span class="arrow"></span></a></p>
                    </div>  
    
                }
    
    
            </div>
        }
    

    I tried to move the @ around but I don't get where it is supposed to go. I'm only at this since October/November!

    Thanks. Tony

  • Tony Groome 261 posts 804 karma points
    Feb 19, 2015 @ 12:00
    Tony Groome
    101

    Got this to work - had to re-order some of the code and stick in an @ in front of the if width

    @foreach(var page in CurrentPage.Children.Reverse().Take(5)) { dynamic image=null; if (page.HasValue("image")) {
    var dynamicMediaItem = Umbraco.Media(page.image); int width = dynamicMediaItem.GetPropertyValue

            <div class="content-page-wide-box">     
    
                @if (width > height)
                {
                    <div class="column w220">
                        <img src="@dynamicMediaItem.GetCropUrl("foundation")" alt="@dynamicMediaItem.Name" style="padding:5px 5px 5px 5px"/>
                    </div>
                    <div class="column w220">
                        <center><span style="line-height: 1.4em; padding:5px 5px 5px 5px;font-size: 16px; font-weight: bold;">@page.Name</span></center>
                    </div>
                    <div class="column w220">
                        <span style="float:right; padding:10px 10px 10px 10px;">@page.summary</span>
                    </div>
                    <div class="column w470">
                        <p><a class="buttonGrey block w220" target="_blank" [email protected] rel="nofollow">@page.Name<span class="arrow"></span></a></p>
                    </div>
                }
                else
                {
                    <div class="column w220">
                        <img src="@dynamicMediaItem.GetCropUrl("portrait")" alt="@dynamicMediaItem.Name" style="padding:5px 5px 5px 5px"/>
                    </div>
                    <div class="column w220">
                        <center><span style="line-height: 1.4em; padding:5px 5px 5px 5px;font-size: 16px; font-weight: bold;">@page.Name</span></center>
                    </div>
                    <div class="column w220">
                        <span style="float:right; padding:10px 10px 10px 10px;">@page.summary</span>
                    </div>
                    <div class="column w470">
                        <p><a class="buttonGrey block w220" target="_blank" [email protected] rel="nofollow">@page.Name<span class="arrow"></span></a></p>
                    </div>  
    
                }
    
    
            </div>
        }
    }
    
  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Feb 19, 2015 @ 12:28
    Jan Skovgaard
    1

    Hi Tony

    Sorry I forgot to get back to you on this one - Glad you found the solution and thanks for sharing :)

    /Jan

  • Tony Groome 261 posts 804 karma points
    Feb 19, 2015 @ 14:07
    Tony Groome
    0

    Hi Jan

    No worries! I was off for a couple of days too - great to get some air!!

    Thanks. Tony

Please Sign in or register to post replies

Write your reply to:

Draft