• Resolved Anonymous User 14978628

    (@anonymized-14978628)


    Hi Stefan,

    I’m having some confusion regarding the selected image sizes which i’m hoping you can clarify for me please.

    My understanding is that by having different image sizes in the srcset, the browser will automatically choose the best size for the display device. So smaller image sizes for smaller screens, and larger sizes for larger screens.

    I have tried to apply this logic to my homepage images by adding sizes for phone, tablet and pc screens based on how the image sizes change responsively for each device (including landscape/portrait orientations). I used the chrome extension “window resizer beta” to determine what these image sizes are.

    This gives me the following sizes which i added to my functions.php

    add_image_size( 'Homepage-iPad-Portrait', 676, 480 );
    add_image_size( 'Homepage-iPad-Portrait@2x', 1352, 960 );
    add_image_size( 'Homepage-iPad-Landscape', 285, 203 );
    add_image_size( 'Homepage-iPad-Landscape@2x', 570, 406 );
    add_image_size( 'Homepage-iPhone6-Portrait', 322, 229 );
    add_image_size( 'Homepage-iPhone6-Portrait@2x', 644, 458 );
    add_image_size( 'Homepage-iPhone6-Landscape', 585, 415 );
    add_image_size( 'Homepage-iPhone6-Landscape@2x', 1170, 830 );
    add_image_size( 'Homepage-iPhone5-Portrait', 273, 194 );
    add_image_size( 'Homepage-iPhone5-Portrait@2x', 546, 388 );
    add_image_size( 'Homepage-iPhone5-Landscape', 496, 352 );
    add_image_size( 'Homepage-iPhone5-Landscape@2x', 992, 704 );
    add_image_size( 'et-builder-portfolio-image@2x', 800, 568 );

    And the code i used for the homepage images was the one you gave before but now including these sizes:

    <a href="<?php echo get_permalink( $post->ID );?>">
                <?php
                $thumbnail_id = get_post_thumbnail_id( $post->ID );
                echo rwp_img( $thumbnail_id, array (
                    'sizes' => array( 'et-builder-portfolio-image@2x', 'Homepage-iPad-Portrait', 'Homepage-iPad-Portrait@2x', 'Homepage-iPad-Landscape', 'Homepage-iPad-Landscape@2x', 'Homepage-iPhone6-Portrait', 'Homepage-iPhone6-Portrait@2x', 'Homepage-iPhone6-Landscape', 'Homepage-iPhone6-Landscape@2x', 'Homepage-iPhone5-Portrait', 'Homepage-iPhone5-Portrait@2x', 'Homepage-iPhone5-Landscape', 'Homepage-iPhone5-Landscape@2x' ),
                ) );
                ?>
                </a>

    The problem i’m having is that when i run Google PageSpeed Insights, it tells me my images need to be optimized. Specifically the larger sized images and retina images.

    I’m confused as to why this is happening as i thought the whole point of having srcset was to be able to display different sized images to different sized screens. So i thought by doing what i’ve done my images would be optimized, but for some reason Google is saying they are not? I have the retina option enabled in Responsify Wp.

    Am i missing something obvious here?

    https://ww.wp.xz.cn/plugins/responsify-wp/

Viewing 15 replies - 61 through 75 (of 76 total)
  • Thread Starter Anonymous User 14978628

    (@anonymized-14978628)

    Thanks for sending the addon. Unfortunately i can’t actually download it right now as my email service is down! Will let you know how i get on as soon as i can try it out.

    The same happens with the Lazy Load XT plugin, but not with A3 Lazy Load. That’s strange since A3 is based on exactly the same scripts. I’ve tried to find what A3 does differently without success so far.

    Yeah, a3 lazy load works perfectly with the custom RWP code. It’s just post images that are a problem. Lazy Load XT works for all images, but it has the retina images problem as you saw. So each plugin kinda half works, half doesn’t. Would be good to combine them into one fully working plugin!

    Plugin Author stefanledin

    (@stefanledin)

    Really strange indeed. I saw that you’d started a thread over at the Lazy Load XT forum the other day. Hope you’ll figure something out there!
    I’m pleased so long as the RWP markup is correct 😉

    Thread Starter Anonymous User 14978628

    (@anonymized-14978628)

    Yeah, i thought it would be worth a go to email the plugin developer. But this seems to be an inherent problem within Lazy Load XT (i realised this when i duplicated the same problem manually installing Lazy Load XT without the plugin). I doubt the developer will look into this further, as it’s rare to find someone as helpful as yourself.

    However, not all is lost! I’ve found that i can use a3 lazy load to give perfect functionality with the custom codes i use with RWP. For the post images, i’ve found my theme has an option to insert images with lazy load automatically, and these images keep the srcset outputted by RWP. It’s not perfect, but the visible and actual image sizes are very close, unlike Lazy Load XT which were massively different.

    An alternative i had looked into was the following plugin:

    https://ww.wp.xz.cn/plugins/adaptive-images/

    This is actually a really good idea where it serves resized images instead of relying on srcset, but it doesn’t offer the level of control that i get with RWP. Still an interesting plugin though.

    Thread Starter Anonymous User 14978628

    (@anonymized-14978628)

    Very useful, thanks!

    Plugin Author stefanledin

    (@stefanledin)

    I doubt the developer will look into this further, as it’s rare to find someone as helpful as yourself.

    =)

    Very useful, thanks!

    Thanks! I’m actually writing on a follow up post right now. I’ve fine tuned my workflow a bit since then 😉

    Plugin Author stefanledin

    (@stefanledin)

    Hi Marty! I’ve tried to answer your emails but they’re just bouncing.
    Anyway, glad everything worked out! 🙂

    Thread Starter Anonymous User 14978628

    (@anonymized-14978628)

    Hi Stefan, sorry about that. I hadn’t updated my mx records yet! ooops 🙂

    Just a quick question.

    When trying out different lazyload plugins i notice that with some of them my images don’t appear using the rwp_attributes code. It results in a 1×1 square pixel where the image should be, although when i inspect the placeholder square my srcset is correctly filled with my media queries:

    <a href="<?php echo get_permalink( $post->ID );?>">
    <?php
    $thumbnail_id = get_post_thumbnail_id( $post->ID );
    $attributes = rwp_attributes( $thumbnail_id, array(
        'element' => 'img',
        'sizes' => array('my sizes' )
    ));
    echo '<img data-srcset="'.$attributes['srcset'].'" sizes="my sizes">';
    ?>
    </a>

    The images do appear with the rwo_img code but of course don’t lazyload:

    <?php
    $thumbnail_id = get_post_thumbnail_id( $post->ID );
    echo rwp_img( $thumbnail_id, array(
        'sizes' => array('my sizes' ),
        'attributes' => array(
            'sizes' => 'my sizes'
        )
    ));
    ?>

    I tried the code for replacing srcset with datasrcset but that also resulted in blank images:

    <a href="<?php echo get_permalink( $post->ID );?>">
    <?php
    $thumbnail_id = get_post_thumbnail_id( $post->ID );
    $img = rwp_img( $thumbnail_id, array(
        'sizes' => array('my sizes' ),
        'attributes' => array(
            'sizes' => 'my sizes'
        )
    ));
    echo str_replace('srcset', 'data-srcset', $img);
    ?>
    </a>

    I was testing with plugins

    BJ Lazy Load
    https://en-gb.ww.wp.xz.cn/plugins/bj-lazy-load/

    and

    Lazy Load
    https://ww.wp.xz.cn/plugins/lazy-load/

    Is there another code i could use to make images show with these plugins?

    Plugin Author stefanledin

    (@stefanledin)

    It results in a 1×1 square pixel where the image should be, although when i inspect the placeholder square my srcset is correctly filled with my media queries:

    This comes from the lazy load plugin.

    Your code example 1 & 3 does exactly the same thing, it’s just two different ways to do it.

    Is there another code i could use to make images show with these plugins?

    No, we have gone through all the different ways to manipulate the output from RWP. As long as the output is correct, it’s not an RWP issue.

    Thread Starter Anonymous User 14978628

    (@anonymized-14978628)

    No, we have gone through all the different ways to manipulate the output from RWP. As long as the output is correct, it’s not an RWP issue.

    Yeah i thought so, but worth checking just incase.

    With the lazy load plugin you sent me i tried it without retina images, but it seems to select the wrong image i think? When i view the srcset it see:

    <img data-srcset="http://localhost/wordpress/wp-content/uploads/2016/08/6-402x251.jpg 402w, http://localhost/wordpress/wp-content/uploads/2016/08/6-691x466.jpg 691w" sizes="(min-width: 981px) 402px, (min-width: 480px) 691px, 402px" src="http://localhost/wordpress/wp-content/uploads/2016/08/6-691x466.jpg" class="lazy-loaded">

    using the following code:

    <a href="<?php echo get_permalink( $post->ID );?>">
    <?php
    $thumbnail_id = get_post_thumbnail_id( $post->ID );
    $attributes = rwp_attributes( $thumbnail_id, array(
        'element' => 'img',
        'sizes' => array('Homepage', 'Homepage2' )
    ));
    echo '<img data-srcset="'.$attributes['srcset'].'" sizes="(min-width: 981px) 402px, (min-width: 480px) 691px, 402px">';
    ?>
        </a>

    I’m i a bit confused because when i inspect the image (fullscreen as a desktop) and hover over the src=url (src=”http://localhost/wordpress/wp-content/uploads/2016/08/6-691×466.jpg&#8221;) i see 402×271 (natural: 691×466). It seems to be selecting the 691px image which, if i have set my media query correct, should only be displayed at a minimum viewport of 480px. As the desktop is over my (min-width: 981px) query, should the natural image not be my 402×251 image? Am i misunderstanding something here?

    Plugin Author stefanledin

    (@stefanledin)

    Does it select the image you’re expecting if you turn off lazy load?

    Thread Starter Anonymous User 14978628

    (@anonymized-14978628)

    If i turn off lazy load with rwp_attributes i get a blank image, so i have to use rwp_img which does select image i expect. Also a3 lazy load selects expected image, except when i hover over src it shows the placeholder image.

    Thread Starter Anonymous User 14978628

    (@anonymized-14978628)

    I have searched the wordpress plugins repository and tried every lazy load plugin available. The only plugins i could get to show images with rwp-attributes code was lazy load xt and a3 lazy load!

    The a3 plugin would be perfect except that when using it with my theme inserted images that have lazy load built in, the image loads too late on scroll. This was the only way i could get post images to show the srcset from rwp.

    This doesn’t happen with the lazy load plugin by the wordpress guys for some reason, as my post images with built in lazy load do load properly:

    https://ww.wp.xz.cn/plugins/lazy-load/

    except that plugin doesn’t work with rwp_attributes so all my custom code images are blank! Oh the joy of lazy loading!

    Thread Starter Anonymous User 14978628

    (@anonymized-14978628)

    Just a thought. Would RWP be compatible with Cloudflare Mirage? If you are familiar with that?

    https://www.cloudflare.com/mirage/

    Thread Starter Anonymous User 14978628

    (@anonymized-14978628)

    Plugin Author stefanledin

    (@stefanledin)

    If i turn off lazy load with rwp_attributes i get a blank image, so i have to use rwp_img which does select image i expect.

    Great, then it’s an issue with the lazy load script.

    I have searched the wordpress plugins repository and tried every lazy load plugin available. The only plugins i could get to show images with rwp-attributes code was lazy load xt and a3 lazy load!

    It all comes down to how they are implementing the solution. I bet that many of them is manipulating the <img>, just like RWP does, so it collides.
    But since Lazy Load XT works, except for retina, I think you should ask yourself if it’s really that important? As I’ve said before, it’s on logos and symbols that you really can tell the difference. If a photo is retina or not isn’t that obvious.
    I think you should ask yourself if lazy loading is this important to. It makes sense on pages with many images, like a gallery or a product list. Or a slider with huge images.
    On something like a news article with a few images, I wouldn’t bother.

    Just a thought. Would RWP be compatible with Cloudflare Mirage? If you are familiar with that?

    Nope, no idea. Never seen that before actually.

    I think we should close this thread soon, we are very far away from the original question 😉

Viewing 15 replies - 61 through 75 (of 76 total)

The topic ‘Selecting Image Size’ is closed to new replies.