• Hi team,

    I’m the developer from LiteSpeed Cache, we found that AMP plugin is not using wp_get_attachment_image_src() or wp_get_attachment_url() to attache the image url to AMP page.

    This lead to a bug that when a user enables an URL replacement function for CDN will not return the correct size of the image.

    e.g.

    Original: https://example.com/image_723x394.png
    After URL replacement: https://cdn.example.com/image.png

    We found this part of function causing this error (url not equal to upload_url after CDN replace)

    
    // Check if $img_url is local.
    if ( false === strpos( $url, $upload_url ) ) {
        // Return the original array
        return array (
            0 => $url,
            1 => $width,
            2 => $height
        );
        //throw new Aq_Exception('Image must be local: ' . $url);
    }
    

    Any solution to this bug?

Viewing 7 replies - 1 through 7 (of 7 total)
  • i have this problem for months. thanks to litespeed, it’s been found finally.

    check the problem on my site: https://tosunkaya.com/amp/

    • This reply was modified 6 years, 4 months ago by tosunkaya.
    Plugin Contributor ampforwp

    (@ampforwp)

    Hi @stanleylitespeed,

    Thank you so much for this info and I will send this code to the lead developers and there will test it and will get back to you once we made any progress.

    Plugin Contributor ampforwp

    (@ampforwp)

    Hi @stanleylitespeed,

    I was working on your issue and I have set up the CDN through your plugin yesterday but still, the images are not appearing through the CDN – https://monosnap.com/file/JO2OVkBliGF25UtlCphjU708DYO8Kq

    And it is showing me like this in image optimization section – https://monosnap.com/file/BTDNH9lNiUEX5yUxyNF7SWmnSBTXmZ and after I enable the CDN option my images have disappeared in amp version and I have also deleted the code which you have suggested but it doesn’t work as the images are not there in CDN URL.

    Will you please help me to recreate the issue on my end and I will try my best to fix this issue as soon as possible.

    Thread Starter stanley@litespeed

    (@stanleylitespeed)

    Hi @ampforwp, I saw you’ve set up a CDN on Litespeed plugin: https://prnt.sc/lg92i6

    Then you can set the DNS of your CDN domain https://cdn.xxx.com/ to your main domain’s IP (https://xxxxxx.com) for testing.

    You don’t need to touch the image optimization function, just setting the CDN can reproduce the error.

    You can also join our Slack channel, or leave any contact method with me, I’m glad to help you in any way.

    Plugin Contributor ampforwp

    (@ampforwp)

    Hi @stanleylitespeed,

    We use wp_get_attachment_image_src to get the images and then if the image is not coming from CDN then we will crop it and if the images are coming from the CDN then it is not possible to crop the sizes because we use the aqua resizer to crop them and it only crops the normal images, not the CDN images So now the images are appearing with the normal size only without cropping.

    So basically you want us to crop the images from CDN also?

    Thread Starter stanley@litespeed

    (@stanleylitespeed)

    Hi @ampforwp,

    I see the point. Yes, the client would like to crop the images from CDN also and we assume the images on CDN server are same as WordPress server.

    Maybe AMP plugin can add a field for user input their CDN URL too for identifying the image is from CDN, and keep the original function remain unchanged.

    Thread Starter stanley@litespeed

    (@stanleylitespeed)

    Hi @ampforwp, may I know is there any update? Thanks!

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Image URL replacement on AMP page not correct’ is closed to new replies.