Custom thumbnail and image sizes
-
Seems this plugin does not’ support registered custom image size (in theme) and generate only base picture sizes of webp or avif.
-
Hi @mutbl,
Does your theme allow you to define additional images sizes, or are you referring to adding images sizes using a function? Please share more details on this and I’d be happy to check.
I’m using the following code:
function my_theme_setup() {
add_image_size(‘my-theme-post-image’, 700, 9999);
}
add_action(‘after_setup_theme’, ‘my_theme_setup’ );Everything is work fine with jpg, but not with webp or avif.
Appreciate the update @mutbl. Do you have the Output fallback images option enabled? If so, what you may be seeing from your media manager at wp-admin may be the JPEG or original file format image. You will need to check the files generated via FTP of your website hosting file manager to view the different variations generated. I tested this and the custom image dimensions I added via add_image_size are resulting in WebP images with these dimensions being added.
There is also an open GitHub issue regarding extending the image generation for fallback images, which you will find below:
https://github.com/WordPress/performance/issues/1513Output fallback images – enabled (also generate fallback images in the original upload format)
username@www:/path/blog/wp-content/uploads/2024/12# ls -la
total 4072
drwxr--r-- 2 username username 4096 Dec 3 13:50 .
drwxr--r-- 5 username username 4096 Dec 1 08:50 ..
-rw-r--r-- 1 username username 37476 Dec 3 13:50 photounsplash-1024x683-jpg.webp
-rw-r--r-- 1 username username 71392 Dec 3 13:50 photounsplash-1024x683.jpg
-rw-r--r-- 1 username username 7236 Dec 3 13:50 photounsplash-150x150-jpg.webp
-rw-r--r-- 1 username username 9336 Dec 3 13:50 photounsplash-150x150.jpg
-rw-r--r-- 1 username username 125868 Dec 3 13:50 photounsplash-1536x1024.jpg
-rw-r--r-- 1 username username 194870 Dec 3 13:50 photounsplash-2048x1365.jpg
-rw-r--r-- 1 username username 10238 Dec 3 13:50 photounsplash-300x200-jpg.webp
-rw-r--r-- 1 username username 15203 Dec 3 13:50 photounsplash-300x200.jpg
-rw-r--r-- 1 username username 43560 Dec 3 13:50 photounsplash-700x469.jpg
-rw-r--r-- 1 username username 26946 Dec 3 13:50 photounsplash-768x512-jpg.webp
-rw-r--r-- 1 username username 48472 Dec 3 13:50 photounsplash-768x512.jpg
-rw-r--r-- 1 username username 105566 Dec 3 13:50 photounsplash-scaled-jpg.webp
-rw-r--r-- 1 username username 285916 Dec 3 13:50 photounsplash-scaled.jpg
-rw-r--r-- 1 username username 3154553 Dec 3 13:50 photounsplash.jpg
username@www:/path/blog/wp-content/uploads/2024/12#Generate the following code at front-end:
source type=”image/webp” srcset=”https://xxxxxxx/wp-content/uploads/2024/12/photounsplash-300×200-jpg.webp 300w, https://xxxxxxx/wp-content/uploads/2024/12/photounsplash-1024×683-jpg.webp 1024w, https://xxxxxxx/wp-content/uploads/2024/12/photounsplash-768×512-jpg.webp 768w” sizes=”(max-width: 700px) 100vw, 700px“
-
This reply was modified 1 year, 6 months ago by
mutbl.
Thanks for the update @mutbl. Based on the output of the newly generated images, I can see some of the 700px wide images generated, including WebP versions. Based on that, all does seem to be working as expected.
Can’t understand why you suppose it’s expected behavior. I suppose this plugin should generate 700px version of webp (not only jpeg) and put it to source tag. But as I can see in source tag only basic sizes defined and not generate webp for 700px size in FS.
-
This reply was modified 1 year, 6 months ago by
mutbl.
Apologies @mutbl, indeed I don’t see any 700px wide image in WebP format from the output you shared. I did perform some additional checks on this and in my case WebP images in custom sizes are generated (screenshot), but only when the Output fallback images option is not enabled.
When checking with the fallback option enabled, WebP images are not generated for custom sizes added via
add_image_size(screenshot). With that, I went ahead and created a GitHub issue for the team to review. Feel free to chime in on that issue, or let me know if there is anything you would like me to add. You’ll find this below:
https://github.com/WordPress/performance/issues/1720Thanks for raising this, and be sure to subscribe to that issue for updates. Unfortunately I don’t have a workaround other than not selecting the fallback option at present, and the team will have to confirm the issue raised.
Just to let you know we are already working on a fix for this, see below:
https://github.com/WordPress/performance/pull/1689Let me know if you have any questions with the above. Thank you.
Good to know, that you and your colleagues already fixed it. Waiting new release with fix to test it 🙂
Many thanks!
-
This reply was modified 1 year, 6 months ago by
The topic ‘Custom thumbnail and image sizes’ is closed to new replies.