• 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 - 1 through 15 (of 76 total)
  • Thread Starter Anonymous User 14978628

    (@anonymized-14978628)

    Forgot to add link to page:

    http://www.celebrityhealthcritic.com/

    Plugin Author stefanledin

    (@stefanledin)

    Hi marty!
    Yeah that’s something PageSpeed Insights always complains about. But the optimization it refers to in this situation is of the image itself. Running the image through some kind of optimization tool in order to remove unnecessary data and stuff…
    You can take a look at plugins like WP Smush that optimizes the images when they are uploaded to WordPress.

    Thread Starter Anonymous User 14978628

    (@anonymized-14978628)

    Hi Stefan. Yeah, I noticed under the mobile section of pagespeed it says that the images are optimized, but it says that they are not optimized for the desktop. Very strange that Google should report it this way. Do you know why this happens with pagespeed? Does it not recognize srcset properly? The obvious question here is if google thinks the images are not optimized for desktop and returns a low pagespeed score, will this not then have a negative effect on rankings?

    I do use Wp Smush already, but disabled all my plugins just so i can focus on this issue to make sure nothing was causing a conflict with Responsify WP.

    Looking at the debug info i’m not sure if retina is being outputted as i don’t see any @2x in the image sizes. Is this something i would only see using a retina screen? My screen is 1080p so i don’t have a retina display currently. Here are my outputted image sizes for the homepage:

    <img srcset="http://www.celebrityhealthcritic.com/wp-content/uploads/2016/07/6-273x184.jpg 273w, http://www.celebrityhealthcritic.com/wp-content/uploads/2016/07/6-285x192.jpg 285w, http://www.celebrityhealthcritic.com/wp-content/uploads/2016/07/6-322x217.jpg 322w, http://www.celebrityhealthcritic.com/wp-content/uploads/2016/07/6-496x334.jpg 496w, http://www.celebrityhealthcritic.com/wp-content/uploads/2016/07/6-546x368.jpg 546w, http://www.celebrityhealthcritic.com/wp-content/uploads/2016/07/6-570x384.jpg 570w, http://www.celebrityhealthcritic.com/wp-content/uploads/2016/07/6-585x394.jpg 585w, http://www.celebrityhealthcritic.com/wp-content/uploads/2016/07/6-644x434.jpg 644w, http://www.celebrityhealthcritic.com/wp-content/uploads/2016/07/6-676x455.jpg 676w, http://www.celebrityhealthcritic.com/wp-content/uploads/2016/07/6-800x539.jpg 800w" sizes="(min-width: 676px) 800px, (min-width: 644px) 676px, (min-width: 585px) 644px, (min-width: 570px) 585px, (min-width: 546px) 570px, (min-width: 496px) 546px, (min-width: 322px) 496px, (min-width: 285px) 322px, (min-width: 273px) 285px, 273px">

    and my debug:

    ### RWP Debug ###
    Attachment ID: 135
    Image sizes: thumbnail, medium, medium_large, large, 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, logo-small, logo-small@2x, logo-large, logo-large@2x, related-posts, smallest, small, medium-large-1200, largest, et-builder-post-main-image, et-builder-post-main-image-fullwidth, et-builder-portfolio-image, et-builder-portfolio-image-single, extra-image-huge, extra-image-single-post, extra-image-medium, extra-image-small, extra-image-square-medium, extra-image-square-small, full
    Image width: 950
    Image height: 640
    Image sizes found: thumbnail, medium_large, et-builder-portfolio-image@2x, Homepage-iPad-Portrait, Homepage-iPad-Landscape, Homepage-iPad-Landscape@2x, Homepage-iPhone6-Portrait, Homepage-iPhone6-Portrait@2x, Homepage-iPhone6-Landscape, Homepage-iPhone5-Portrait, Homepage-iPhone5-Portrait@2x, Homepage-iPhone5-Landscape, logo-small, logo-small@2x, logo-large, logo-large@2x, related-posts, smallest, small, et-builder-post-main-image, et-builder-portfolio-image, extra-image-single-post, extra-image-medium, extra-image-small, extra-image-square-medium, extra-image-square-small, full
    Images found:
    - thumbnail: http://www.celebrityhealthcritic.com/wp-content/uploads/2016/07/6-150x101.jpg,
    - medium_large: http://www.celebrityhealthcritic.com/wp-content/uploads/2016/07/6-768x517.jpg,
    - et-builder-portfolio-image@2x: http://www.celebrityhealthcritic.com/wp-content/uploads/2016/07/6-800x539.jpg,
    - Homepage-iPad-Portrait: http://www.celebrityhealthcritic.com/wp-content/uploads/2016/07/6-676x455.jpg,
    - Homepage-iPad-Landscape: http://www.celebrityhealthcritic.com/wp-content/uploads/2016/07/6-285x192.jpg,
    - Homepage-iPad-Landscape@2x: http://www.celebrityhealthcritic.com/wp-content/uploads/2016/07/6-570x384.jpg,
    - Homepage-iPhone6-Portrait: http://www.celebrityhealthcritic.com/wp-content/uploads/2016/07/6-322x217.jpg,
    - Homepage-iPhone6-Portrait@2x: http://www.celebrityhealthcritic.com/wp-content/uploads/2016/07/6-644x434.jpg,
    - Homepage-iPhone6-Landscape: http://www.celebrityhealthcritic.com/wp-content/uploads/2016/07/6-585x394.jpg,
    - Homepage-iPhone5-Portrait: http://www.celebrityhealthcritic.com/wp-content/uploads/2016/07/6-273x184.jpg,
    - Homepage-iPhone5-Portrait@2x: http://www.celebrityhealthcritic.com/wp-content/uploads/2016/07/6-546x368.jpg,
    - Homepage-iPhone5-Landscape: http://www.celebrityhealthcritic.com/wp-content/uploads/2016/07/6-496x334.jpg,
    - logo-small: http://www.celebrityhealthcritic.com/wp-content/uploads/2016/07/6-104x70.jpg,
    - logo-small@2x: http://www.celebrityhealthcritic.com/wp-content/uploads/2016/07/6-208x140.jpg,
    - logo-large: http://www.celebrityhealthcritic.com/wp-content/uploads/2016/07/6-184x124.jpg,
    - logo-large@2x: http://www.celebrityhealthcritic.com/wp-content/uploads/2016/07/6-368x248.jpg,
    - related-posts: http://www.celebrityhealthcritic.com/wp-content/uploads/2016/07/6-212x143.jpg,
    - smallest: http://www.celebrityhealthcritic.com/wp-content/uploads/2016/07/6-479x323.jpg,
    - small: http://www.celebrityhealthcritic.com/wp-content/uploads/2016/07/6-768x517.jpg,
    - et-builder-post-main-image: http://www.celebrityhealthcritic.com/wp-content/uploads/2016/07/6-400x250.jpg,
    - et-builder-portfolio-image: http://www.celebrityhealthcritic.com/wp-content/uploads/2016/07/6-400x284.jpg,
    - extra-image-single-post: http://www.celebrityhealthcritic.com/wp-content/uploads/2016/07/6-950x640.jpg,
    - extra-image-medium: http://www.celebrityhealthcritic.com/wp-content/uploads/2016/07/6-627x376.jpg,
    - extra-image-small: http://www.celebrityhealthcritic.com/wp-content/uploads/2016/07/6-440x264.jpg,
    - extra-image-square-medium: http://www.celebrityhealthcritic.com/wp-content/uploads/2016/07/6-440x440.jpg,
    - extra-image-square-small: http://www.celebrityhealthcritic.com/wp-content/uploads/2016/07/6-150x150.jpg,
    - full: http://www.celebrityhealthcritic.com/wp-content/uploads/2016/07/6.jpg

    At the end of the debug i noticed the following media queries. Could you tell me if these are set by Responsify WP automatically or is this due to my theme css?

    Media queries:
    - Use Homepage-iPad-Landscape when min-width: 273px,
    - Use Homepage-iPhone6-Portrait when min-width: 285px,
    - Use Homepage-iPhone5-Landscape when min-width: 322px,
    - Use Homepage-iPhone5-Portrait@2x when min-width: 496px,
    - Use Homepage-iPad-Landscape@2x when min-width: 546px,
    - Use Homepage-iPhone6-Landscape when min-width: 570px,
    - Use Homepage-iPhone6-Portrait@2x when min-width: 585px,
    - Use Homepage-iPad-Portrait when min-width: 644px,
    - Use et-builder-portfolio-image@2x when min-width: 676px

    I was also trying to do something similiar with my logo by adding custom sizes to the code you gave me but was having trouble getting those sizes to appear as i do for the homepage images. Could you tell me how to correctly add sizes to my code please? The code i tried was:

    <a class="logo" href="<?php echo esc_url( home_url( '/' ) ); ?>" data-fixed-height="<?php echo esc_attr( et_get_option( 'fixed_nav_logo_height', '51' ) ); ?>">
                    <?php
                        echo rwp_img( 153, array(
                        'attributes' => array(
    			'sizes' => 'imagesize1', 'imagesize2', 'imagesize3' ,
                        'id' => 'logo',
                        'alt' => esc_attr( get_bloginfo( 'name' ) )
                        )
                        ) );
                    ?>
            </a>
    Plugin Author stefanledin

    (@stefanledin)

    Hi Stefan. Yeah, I noticed under the mobile section of pagespeed it says that the images are optimized, but it says that they are not optimized for the desktop. Very strange that Google should report it this way. Do you know why this happens with pagespeed? Does it not recognize srcset properly? The obvious question here is if google thinks the images are not optimized for desktop and returns a low pagespeed score, will this not then have a negative effect on rankings?

    I don’t know. Maybe the full size image is being used and Google doesn’t consider it to be optimized enough.

    Based on the <img> you posted, this seams to be the image sizes used:

    Homepage-iPhone5-Portrait:
    http://www.celebrityhealthcritic.com/wp-content/uploads/2016/07/6-273x184.jpg
    
    Homepage-iPhone5-Portrait@2x
    http://www.celebrityhealthcritic.com/wp-content/uploads/2016/07/6-546x368.jpg 546w,
    
    Homepage-iPad-Landscape
    http://www.celebrityhealthcritic.com/wp-content/uploads/2016/07/6-285x192.jpg 285w,
    
    Homepage-iPad-Landscape@2x
    http://www.celebrityhealthcritic.com/wp-content/uploads/2016/07/6-570x384.jpg 570w,
    
    Homepage-iPhone6-Portrait
    http://www.celebrityhealthcritic.com/wp-content/uploads/2016/07/6-322x217.jpg 322w,
    
    Homepage-iPhone6-Portrait@2x
    http://www.celebrityhealthcritic.com/wp-content/uploads/2016/07/6-644x434.jpg 644w,
    
    Homepage-iPhone5-Landscape
    http://www.celebrityhealthcritic.com/wp-content/uploads/2016/07/6-496x334.jpg 496w,
    
    Homepage-iPhone6-Landscape
    http://www.celebrityhealthcritic.com/wp-content/uploads/2016/07/6-585x394.jpg 585w,
    
    Homepage-iPad-Portrait
    http://www.celebrityhealthcritic.com/wp-content/uploads/2016/07/6-676x455.jpg 676w,
    
    et-builder-portfolio-image@2x
    http://www.celebrityhealthcritic.com/wp-content/uploads/2016/07/6-800x539.jpg 800w

    A side note, the retina sizes doesn’t have ‘@2x’ in the filename which people seems to believe.

    At the end of the debug i noticed the following media queries. Could you tell me if these are set by Responsify WP automatically or is this due to my theme css?

    Your CSS doesn’t affect the output from RWP.

    I was also trying to do something similiar with my logo by adding custom sizes to the code you gave me but was having trouble getting those sizes to appear as i do for the homepage images. Could you tell me how to correctly add sizes to my code please? The code i tried was:

    <?php
    echo rwp_img( 153, array(
        'attributes' => array(
            'sizes' => 'imagesize1', 'imagesize2', 'imagesize3' ,
        'id' => 'logo',
        'alt' => esc_attr( get_bloginfo( 'name' ) )
        )
    ) );
    ?>

    You’re editing the sizes attribute in this case. This is how you select which image sizes that should be used:

    <?php
    echo rwp_img( 153, array(
        'sizes' => array('imagesize1', 'imagesize2', 'imagesize3'),
        'id' => 'logo',
        'alt' => esc_attr( get_bloginfo( 'name' ) )
        )
    ) );
    ?>
    Thread Starter Anonymous User 14978628

    (@anonymized-14978628)

    Thanks, will try this tomorrow. Head hurts from trying to figure out all this stuff today!

    Just realized though that i totally overlooked the custom media queries section in the plugin. I saw this before but didn’t really understand it’s use until now when trying to figure out why certain image sizes weren’t showing as expected. Looks like a very useful feature!

    Could you tell me if Responsify WP has some sort of caching enabled in it? I was changing image sizes in my template code and this wasn’t being reflected immediately when the page was displayed, even after refreshing the page.

    I’m working with a local test site and was clearing browser cache after making the changes, but it was like the old code was still being displayed for some reason?

    Plugin Author stefanledin

    (@stefanledin)

    Nope, no caching. You doesn’t have any other caching plugin? Or changing the wrong code?

    Thread Starter Anonymous User 14978628

    (@anonymized-14978628)

    I think the problem i’m having is due to not setting the media queries properly.

    What i’m trying to do is display a certain image size only for a certain viewpoint using the following code:

    <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', 'Homepage-iPad-Portrait', 'Homepage-iPad-Landscape' ),
    
    'media_queries' => array(
                'et-builder-portfolio-image' => 'min-width: 1405px',
                'Homepage-iPad-Portrait' => 'min-width: 768px', 'max-width: 980px',
                'Homepage-iPad-Landscape' => 'min-width: 981px', 'max-width: 1100px'
            ))
    
    );
                ?>
                </a>

    For example, I would like to display et-builder-portfolio-image for desktops only starting with min-width: 1405px for the viewport size, and display Homepage-iPad-Portrait only for viewport sizes min-width: 768px-max-width: 980px, and Homepage-iPad-Landscape only for viewport sizes min-width: 981px-max-width: 1100px.

    But when i look at the debug it shows the following media queries:

    Media queries:
    – Use et-builder-portfolio-image when max-width: 980px,
    – Use Homepage-iPad-Portrait when max-width: 980px

    For some reason in the debug the media query for et-builder-portfolio-image is being outputted as max-width: 980px when i specified min-width: 1405px. Homepage-iPad-Portrait seems to be outputting correctly at max-width: 980px, but Homepage-iPad-Landscape is absent from the media query debug info entirely.

    I’m not sure what i’m doing wrong here? How i can specify a certain image size to only be shown at a specified viewport size?

    Plugin Author stefanledin

    (@stefanledin)

    'media_queries' => array(
        'et-builder-portfolio-image' => 'min-width: 1405px',
        'Homepage-iPad-Portrait' => 'min-width: 768px', 'max-width: 980px',
        'Homepage-iPad-Landscape' => 'min-width: 981px', 'max-width: 1100px'
    )

    You can’t assign multiple media queries to an image size. The syntax itself is wrong to. The code above corresponds to this:

    'media_queries' => array(
        'et-builder-portfolio-image' => 'min-width: 1405px',
        'Homepage-iPad-Portrait' => 'min-width: 768px',
        'max-width: 980px',
        'Homepage-iPad-Landscape' => 'min-width: 981px',
        'max-width: 1100px'
    )

    Anyway, I would suggest that you try to think about how the generated <img>element should look like. If you understand how it works and know how you’d write it “manually”, I think it’s easier to wrap your head around how to do it with RWP.

    This code would be enough:

    echo rwp_img( $thumbnail_id, array (
        'sizes' => array( 'et-builder-portfolio-image', 'Homepage-iPad-Portrait', 'Homepage-iPad-Landscape' ),
        'media_queries' => array(
            'et-builder-portfolio-image' => 'min-width: 1405px',
            'Homepage-iPad-Landscape' => 'min-width: 981px'
        )
    ) );

    Homepage-iPad-Portrait would be used on screens smaller than 768px. Homepage-iPad-Landscape will be selected when the screen is larger than 981 (but smaller than 1405 of course). et-builder-portfolio-image will be used when the screen is larger than 1405px.

    Thread Starter Anonymous User 14978628

    (@anonymized-14978628)

    Homepage-iPad-Portrait would be used on screens smaller than 768px. Homepage-iPad-Landscape will be selected when the screen is larger than 981 (but smaller than 1405 of course). et-builder-portfolio-image will be used when the screen is larger than 1405px.

    Should the code include Homepage-iPad-Portrait also as it’s missing from the code you wrote:

    echo rwp_img( $thumbnail_id, array (
        'sizes' => array( 'et-builder-portfolio-image', 'Homepage-iPad-Portrait', 'Homepage-iPad-Landscape' ),
        'media_queries' => array(
            'et-builder-portfolio-image' => 'min-width: 1405px',
            'Homepage-iPad-Landscape' => 'min-width: 981px'
        )
    ) );

    Would i include it like this?

    echo rwp_img( $thumbnail_id, array (
        'sizes' => array( 'et-builder-portfolio-image', 'Homepage-iPad-Portrait', 'Homepage-iPad-Landscape' ),
        'media_queries' => array(
            'et-builder-portfolio-image' => 'min-width: 1405px',
            'Homepage-iPad-Landscape' => 'min-width: 981px',
    'Homepage-iPad-Portrait' => 'min-width: 768px'
        )
    ) );
    Thread Starter Anonymous User 14978628

    (@anonymized-14978628)

    I think it's easier to wrap your head around how to do it with RWP

    Do you mean setting the media queries within RWP settings and just specifying the images in the code like:

    ID );?>”>
    <?php
    $thumbnail_id = get_post_thumbnail_id( $post->ID );
    echo rwp_img( $thumbnail_id, array (
    ‘sizes’ => array( ‘image1’, ‘image2’, ‘image3’ ),
    ) );
    ?>

    That was what i tried initially but it wasn’t working which is why i tried to manually add it in the code.

    Plugin Author stefanledin

    (@stefanledin)

    Should the code include Homepage-iPad-Portrait also as it’s missing from the code you wrote:

    You don’t have to specify any media queries for the smallest image size.

    Example:
    Let’s say that we have these three versions of the same image:

    • thumbnail.jpg (150x150px)
    • medium.jpg (300x300px)
    • large.jpg (1024x1024px)

    An <img> for this image would look like this:

    <img srcset="large.jpg 1024w, medium.jpg 300w, thumbnail.jpg 150w" sizes="(min-width: 300px) 1024px, (min-width: 150px) 300px, 150px">

    That’s the markup RWP would generate per default by using this function:

    echo rwp_img($id);

    If you only wanna use medium and large, you would do this:

    echo rwp_img($id, array(
        'sizes' => array('medium', 'large')
    ));

    That would generate:

    <img srcset="large.jpg 1024w, medium.jpg 300w" sizes="(min-width: 300px) 1024px, 300px">

    large.jpg would be selected on screens that is at least 300px wide. On smaller screens, medium.jpg would be used.

    But what if you wanna use medium.jpg on larger screens?

    <img srcset="large.jpg 1024w, medium.jpg 300w" sizes="(min-width: 768px) 1024px, 300px">

    Okey, medium.jpg will be used on screens smaller than 768px now.

    Here’s how to accomplish the same markup with RWP:

    echo rwp_img($id, array(
        'sizes' => array('medium', 'large'),
        'media_queries' => array(
            'large' => 'min-width: 768px'
        )
    ));

    Or, an alternative way is to do this:

    echo rwp_img($id, array(
        'sizes' => array('medium', 'large'),
        'attributes' => array(
            'sizes' => '(min-width: 768px) 1024px, 300px'
        )
    ));
    Thread Starter Anonymous User 14978628

    (@anonymized-14978628)

    Is it correct to replace

    echo rwp_img($id, array(

    with

    echo rwp_img( $thumbnail_id, array

    As using the previous code doesn’t output any images?

    The full code i am using based on your examples is:

    <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', 'Homepage-iPad-Landscape', 'Homepage-iPad-Portrait' ),
        'media_queries' => array(
            'et-builder-portfolio-image' => 'min-width: 1405px',
    'Homepage-iPad-Landscape' => 'min-width: 1024px',
        )
    ));
    ?>

    My understanding of this is that et-builder-portfolio-image will only be displayed on screens at least 1405px wide. Homepage-iPad-Landscape only on screens at least 1024px wide. And screens smaller than 1024px Homepage-iPad-Portrait will be displayed. Is my understanding of the code correct?

    What i’m unsure of, is that if my understanding of the code is correct, and et-builder-portfolio-image will only be displayed on screens at least 1405px wide, then why do my images display at different heights?

    Normally, if i only have 1 image size selected in the code (that being et-builder-portfolio-image) all the images display on the homepage the same height. But when i try add in other image sizes for different screen sizes, suddenly my homepage images display at a different height which seems to suggest that et-builder-portfolio-image is not being used for screens larger than 1405px.

    However, looking at the debug, it tells me it is being used at that size

    Media queries:
    - Use et-builder-portfolio-image when min-width: 1405px

    I don’t see the media query there for Homepage-iPad-Landscape though. I was expecting to see also:

    - Use Homepage-iPad-Landscape when min-width: 1024px

    So i know that when i use et-builder-portfolio-image my images display correctly. But when i don’t use that they don’t. I would have expected (if i have implemented the code correctly) that the homepage images would all display correctly with the same height, because only that image size should be displayed on screens at least 1405px wide. But for some reason they don’t?

    Thread Starter Anonymous User 14978628

    (@anonymized-14978628)

    Example.

    Using the code i pasted previously but taking out the other image sizes (leaving everything else in place just for this example) produces images that are all the same height.

    <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' ),
        'media_queries' => array(
            'et-builder-portfolio-image' => 'min-width: 1405px'
        )
    ));
    ?>
                </a>
    Plugin Author stefanledin

    (@stefanledin)

    Is it correct to replace…

    Yes!

    My understanding of this is that et-builder-portfolio-image will only be displayed on screens at least 1405px wide. Homepage-iPad-Landscape only on screens at least 1024px wide. And screens smaller than 1024px Homepage-iPad-Portrait will be displayed. Is my understanding of the code correct?

    Exactly!

    What i’m unsure of, is that if my understanding of the code is correct, and et-builder-portfolio-image will only be displayed on screens at least 1405px wide, then why do my images display at different heights?

    et-builder-portfolio-image is the only image size that is being cropped, right? That explains why images in that size has the same height, but not the others.

    I did realize however that you can’t specify media queries in that way when you’re using rwp_img(). It’s when you’re using the <picture> element and rwp_picture() you should do that. I’ve actually written that in the documentation, but I forgot it myself! 😀 Sorry about that.

    When using rwp_img(), you should override the sizes attribute.
    I think this code should do it:

    <?php
    $thumbnail_id = get_post_thumbnail_id( $post->ID );
    echo rwp_img( $thumbnail_id, array(
        'sizes' => array('et-builder-portfolio-image', 'Homepage-iPad-Landscape', 'Homepage-iPad-Portrait' ),
        'attributes' => array(
            'sizes' => '(min-width: 1405px) 400px, (min-width: 1024px) 285px, 676px'
        )
    ));
    ?>

    What this means:

    Screen width 0-1023px
    Homepage-iPad-Portrait (676px)
    Screen width 1024-1404px
    Homepage-iPad-Landscape (285px)
    Screen width 1405px+
    et-builder-portfolio-image (Since the @2x version is 800, I assume it’s 400px)

    Thread Starter Anonymous User 14978628

    (@anonymized-14978628)

    ok, this appears to be working! Code you please check my code to make sure all is in order:

    <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', 'Homepage-Laptop', 'Homepage-Tablet-Portrait', 'Homepage-Tablet-Landscape', 'Homepage-Smartphone-Large-Portrait', 'Homepage-Smartphone-Large-Landscape', 'Homepage-Smartphone-Small-Portrait', 'Homepage-Smartphone-Small-Landscape' ),
        'attributes' => array(
            'sizes' => '(min-width: 1405px) 400px, (min-width: 1100px) 354px, (min-width: 1024px) 285px, (min-width: 768px) 676px, (min-width: 667px) 585px, (min-width: 568px) 496px, (min-width: 375px) 322px, 273px'
        )
    ));
    ?>
    </a>

    The Last image size (273px-Homepage-Smartphone-Small-Portrait) I did not specify the min-width as you said this is not required for the smallest image size.

    This is based on the viewport size and the resulting image size displayed at that viewport as follows:

    Desktop (viewport min=1405+) (image=402x285)
    Laptop (viewport min=1100) (image=354x252)
    
    Tablet Portrait (viewport=768x1024) (image=676x480)
    Tablet Landscape (viewport=1024x768) (image=285x203)
    
    Smartphone Large Portrait (viewport=375x667) (image=322x229)
    Smartphone Large Landscape (viewport=667x375) (image=585x415)
    
    Smartphone Small Portrait (viewport=320x568) (image=273x194)
    Smartphone Small Landscape (viewport=568x320) (image=496x352)

    (I am using et-builder-portfolio-image (400 x 284) for desktop (min=1405px) which was built into my theme).

    And with that information i took the minimum viewport size for each viewport and listed the image size name followed by the image width as follows:

    Desktop (viewport min=1405+) = et-builder-portfolio-image 400
    Laptop (viewport min=1100) = Homepage-Laptop 354
    Tablet Landscape (viewport min=1024) = Homepage-Tablet-Landscape 285
    Tablet Portrait (viewport min=768) = Homepage-Tablet-Portrait 676
    Smartphone Large Landscape (viewport min=667) = Homepage-Smartphone-Large-Landscape 585
    Smartphone Small Landscape (viewport min=568) = Homepage-Smartphone-Small-Landscape 496
    Smartphone Large Portrait (viewport min=375) = Homepage-Smartphone-Large-Portrait 322
    Smartphone Small Portrait (viewport min=320) = Homepage-Smartphone-Small-Portrait 273

    Creating the following for functions.php

    add_image_size( 'Homepage-Laptop', 354, 252, true );
    
    add_image_size( 'Homepage-Tablet-Portrait', 676, 480, true );
    add_image_size( 'Homepage-Tablet-Landscape', 285, 203, true );
    
    add_image_size( 'Homepage-Smartphone-Large-Portrait', 322, 229, true );
    add_image_size( 'Homepage-Smartphone-Large-Landscape', 585, 415, true );
    
    add_image_size( 'Homepage-Smartphone-Small-Portrait', 273, 194, true );
    add_image_size( 'Homepage-Smartphone-Small-Landscape', 496, 352, true );
Viewing 15 replies - 1 through 15 (of 76 total)

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