Support » Plugin: Product Video Gallery for Woocommerce » Incorrect gallery thumbnail image size is used

  • Resolved Gal Baras

    (@galbaras)


    Revisiting this issue yet again.

    The image size displayed in the thumbnail slider is thumbnail (150×150), although the dimensions of the IMG tag are set correctly to those of woocommerce_gallery_thumbnail.

    This is likely due to the following line:

    $product_video_thumb_url = wp_get_attachment_image_url( $product_video_thumb_id );

    Because wp_get_attachment_image_url() defaults to the thumbnail size.

    This line should change to:

    
    $product_video_thumb_url = wp_get_attachment_image_url( $product_video_thumb_id, apply_filters( 'woocommerce_gallery_thumbnail_size', 'woocommerce_gallery_thumbnail' ) );
    

    Further down, there’s another issue:

    
    $gallery_thumbnail = wc_get_image_size( 'gallery_thumbnail' );
    $thumbnail_size    = apply_filters( 'woocommerce_gallery_thumbnail_size', 'thumbnail' );
    

    The result of the first line isn’t used in the second, and without any custom filters, it results in $thumbnail_size being set to thumbnail. In fact, the value of $gallery_thumbnail isn’t used anywhere below the line that sets it.

    These lines should be replaced with:

    $thumbnail_size = apply_filters( 'woocommerce_gallery_thumbnail_size', 'woocommerce_gallery_thumbnail' );

    But this only changes the image URLs, and we also need to change the dimensions in the IMG tag.

    So in the function get_video_thumbanil_html(), there is direct use of
    get_option( 'thumbnail_size_w' ) and get_option( 'thumbnail_size_h' ). Instead, the function should get either $thumbnail_size as an argument or $props from its called, and use wp_get_attachment_image_src() to get the width and height.

    wp_get_attachment_image_src() can be used instead of wp_get_attachment_image_url() to get the URL and the dimensions in one call.

    BTW, the function get_video_thumbanil_html() contains a typo and should probably be renamed nickx_get_video_thumnbnail_html(), which will also prevent potential name clashes.

    The page I need help with: [log in to see the link]

Viewing 10 replies - 1 through 10 (of 10 total)
  • Plugin Author NikHiL Gadhiya

    (@nikhilgadhiya)

    Hello @galbaras,
    Thank you for suggestions I’ll implement your suggestions and release update on end of the month.

    Thank You.

    Plugin Author NikHiL Gadhiya

    (@nikhilgadhiya)

    Hello,
    I’ve fixed the issue release update please update plugin on your site.

    Thank You.

    Thread Starter Gal Baras

    (@galbaras)

    @nikhilgadhiya Thank you for making changes.

    Unfortunately, the image width and height are still set using get_option( 'thumbnail_size_w' ) and get_option( 'thumbnail_size_h' ), instead of getting the correct ones using wp_get_attachment_image_src().

    Thanks again!

    Thread Starter Gal Baras

    (@galbaras)

    Plugin Author NikHiL Gadhiya

    (@nikhilgadhiya)

    Hello @galbaras,
    I’ve fixed it but I’m working on other bugs. I’ll fix it and release an update soon.

    Thank You.

    Plugin Author NikHiL Gadhiya

    (@nikhilgadhiya)

    Hello @galbaras,
    We’ve fixed the issue and released an update. Please update the plugin with the latest version.

    Thank You.

    Thread Starter Gal Baras

    (@galbaras)

    The new code I get now is

    
    <img width="138" height="207" data-skip-lazy="" global-thumb="" src="https://www.taniaolsen.com.au/wp-content/uploads/2021/11/Screenshot-2021-11-19-150109-138x207.jpg" custom_thumbnail="yes" class="product_video_img img_0 attachment-thumbnail size-thumbnail" alt="" sizes="(max-width: 150px) 100vw, 150px">
    

    As you can see, 150 is still the size in the sizes attribute. Also, the alt attribute is empty, which makes the HTML invalid, and the page not accessible.

    Here’s the code generated by my filter function for comparison (EWWW Image Optimizer can optimise its delivery via its filters, which isn’t happening with your generated code):

    
    <img width="138" height="207" global-thumb="" src="https://www.taniaolsen.com.au/wp-content/uploads/2021/11/Screenshot-2021-11-19-150109-138x207.jpg" custom_thumbnail="yes" class="product_video_img img_0 attachment-thumbnail size-thumbnail ls-is-cached lazyloaded" alt="Product video" sizes="(max-width: 138px) 100vw, 138px" data-src="https://www.taniaolsen.com.au/wp-content/uploads/2021/11/Screenshot-2021-11-19-150109-138x207.jpg" decoding="async" style="height: 145.5px; width: 97px;">
    
    Plugin Author NikHiL Gadhiya

    (@nikhilgadhiya)

    Hello @galbaras,
    We will fixed it in next release.

    Thank You.

    Thread Starter Gal Baras

    (@galbaras)

    Any idea when this may be?

    Plugin Author NikHiL Gadhiya

    (@nikhilgadhiya)

    Hello @galbaras,
    We will fix the issue and release update on the middle of this month.

    Thank You.

Viewing 10 replies - 1 through 10 (of 10 total)
  • You must be logged in to reply to this topic.