Is there a way to generate on the fly, an image size that doesn’t already exist ?
For example, in my theme, it would be nice if I could get an image size with a function like :
get_image_size($image_id, $length, $width, $cropped)
If the image already exist, WordPress could serve me that image (image object or just the URL), if not, WordPress could generate this new image in the right folder (it will be a little bit longer for the first time).
There is some native or custom function to achieve this ?
Thank you
you could add a new image size in your functions.php using add_image_size
and then use wp_get_attachment_image or wp_get_attachment_image_src to get the image.
However, using add_image_size doesn’t create the files for previously uploaded images. In this case, you’ll need to regenerate your thumbnails image. In this case you can use the regenerate thumbnails plugin (this is suggested in the codex)
Also, it seems that using OTF Regenerate Thumbnails could help generating the images on the fly, but I haven’t used it, so not sure how it works. More info about it on github.