Curl get filesize of WEBP images on Shopify CDN not returning correct size

For example, I upload a webp photo into ADMIN > SETTINGS > FILES, and it shows as 65KB.

However when I try to get the filesize using a curl function on my server it shows as 120KB.

If I save it directly from the browser, it comes out to 65KB.

My curl function works perfectly fine for JPG, PNG, GIF. But doesn’t work correctly for WEBP.

Any reason why? Anybody have solution using a curl function?

Are you sure it’s a webp being returned and not a jpeg? What’s the file url?

Of course I’m sure. Here’s the answer/hack if anyone needs it. Simple remote fetch commands won’t fetch a webp file size that matches the size displayed in the shopify admin - which creates confusion. This one will. It should be refactored into a php curl function but I haven’t had the time to strip it down.

$url = “https://cnd.shopify.com/example-image.webp”;

$output = shell_exec(“curl ‘$url’
-H ‘authority: cdn.shopify.com
-H ‘accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,/;q=0.8,application/signed-exchange;v=b3;q=0.9’
-H ‘accept-language: en-US;q=0.7’
-H ‘cache-control: max-age=0’
-H ‘sec-fetch-dest: document’
-H ‘sec-fetch-mode: navigate’
-H ‘sec-fetch-site: none’
-H ‘sec-fetch-user: ?1’
-H ‘sec-gpc: 1’
-H ‘upgrade-insecure-requests: 1’
-H ‘user-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.5060.53 Safari/537.36’
–compressed --silent”);

$size = strlen($output);