• Resolved Frederic Pilon

    (@frederic-pilon)


    Hello!

    I’m using Litespeed on my website, but when I go get an image with get_attachment_by_id it gives me the png/jpg image.

    I still want that, so I can get the fallback, but is there a function that I can call where I would pass the id of the attachment (or the attachment URL) and then it gives me back the webp of the image back (if it exists.)

    Because right now my way of doing so is basically fumbling around with file_exists to check if the file + .webp exists, and if it does, load that image. But that is pretty server intensive and doesn’t seem to always work.

    So is there a function that I can just give a image ID or URL and litespeed gives back the related webp url?

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Support qtwrk

    (@qtwrk)

    Hi,

    Unfortunately no

    and actually that’s exactly the same way when LSCWP does webp replace ment , code:

    https://github.com/litespeedtech/lscache_wp/blob/1460e4550c5d95c28502a856bc4d94459c888868/src/utility.cls.php#L780

    when doing webp replacement

    Best regards,

    Thread Starter Frederic Pilon

    (@frederic-pilon)

    Hunh ok.

    IDK what I did wrong because Litespeed doesn’t seem to pickup my images and replace them to a webp. Thats why I’m trying to put in a <picture> tag that contains both the Webp and JPG/PNG.

    If you are a member of the Litespeed team, could I request such a function be added?

    Plugin Support qtwrk

    (@qtwrk)

    Hi,

    LSCWP itself only filters over <img tag for images , and then check against file.jpg.webp with attached .webp , to see if file exists or not , if exists, then repalce it

    I will pass it onto our devs as feature request, but I don’t see if there is better way than what you are currently doing

    if you worry about IO , you can simply store that info into database or object cache ?

    Best regards,

    Thread Starter Frederic Pilon

    (@frederic-pilon)

    Yeah right now thats what I do.

    I fumble around with a file exist, try to find if the image does exist.

    If it does, I save that responding url in a transient (no expiration). If I can’t find it, I save false in the transient for 24h (in case the LSCWP is still in the process of creating the webps.)

    It’s just a very ‘duct tape’ solution to my liking. (A duct tape solution is a solution that works, but is definitely not a solid fix that should stay as is.)

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Function to get the Webp related to an image’ is closed to new replies.