Get Unregistered Image Size in Wordpress

Is there a way to generate on the fly an image size that doesn't exist yet? For example, in my theme, it would be nice if I could get the image size with a function like:

get_image_size($image_id, $length, $width, $cropped)

      

If the image already exists, Wordpress can help me with this image (an image object or just a URL), if not, Wordpress can generate this new image in the right folder (it will be a little longer the first time).

Is there any native or custom function to achieve this?

thank

+3


source to share


1 answer


you can add new image size to 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 does not create files for previously loaded images. In this case, you will need to restore the thumbnail image. In this case you can use regenerate plugin thumbnails (this is suggested in the codex)



Also, it seems that using the OTF Regenerate Thumbnails can help generate images on the fly, but I haven't used it so I'm not sure how it works. More on this in github .

0


source







All Articles