simply icon indicating copy to clipboard operation
simply copied to clipboard

Use img_url helper to convert image formats automatically

Open yogeshbeniwal opened this issue 1 year ago • 4 comments

Ghost 5.7.0, has added the functionality of the img_url helper, it now can convert image formats automatically. Can use this feature to serve smaller size images with webp extension providing same image quality to enhance performance.

yogeshbeniwal avatar Aug 10 '22 15:08 yogeshbeniwal

wow cool feature, but the size is not always smaller.

For my website images, I use the following formula. I distribute them using nginx bypassing the call to Ghost, I also optimized all the images by losslessly compressing them and making a copy of each image in webp.

Thus, if I have webp, then I give it away, if it doesn’t exist, then I give the picture using nginx, and only if it is not in the folder yet, this happens with new pictures, then we send a request to ghost and it creates pictures in its directories and further they will be distributed from there.

It was for general education, suddenly it will be useful to someone, the essence of my message is different. I had jpg pictures weighing 43 kilobytes, after converting to webp they became all 141 kilobytes, I don’t know why, I also thought that webp should be smaller

uPagge avatar Aug 12 '22 17:08 uPagge

@uPagge Can you share nginx configuration changes and other settings change you are doing to serve images?

yogeshbeniwal avatar Aug 13 '22 04:08 yogeshbeniwal

Sure, here you are

location ~* ^(/blog/content/images/)(.+)\.(png|jpe?g)$ {	
        expires max;
        alias /var/struchkov.dev/ghost/www/images;
        set $webp_image_subdir "/webp/";
        set $basename $2;
        try_files $webp_image_subdir$basename$webp_suffix $uri @ghost;
}

/var/struchkov.dev/ghost/www/images - full path to images /var/struchkov.dev/ghost/www/images/wepb/ - full path to webp images

uPagge avatar Aug 13 '22 08:08 uPagge

By the way, I tried this function, but for some reason my images were not converted using Ghost

uPagge avatar Aug 13 '22 13:08 uPagge