Is there a function I can use to check if a particular image style for a given image has been created already?

link|improve this question

feedback

1 Answer

up vote 3 down vote accepted

I couldn't find one in the core files but fortunately it's pretty straightforward to implement:

function image_style_path_exists($style_name, $path) {
  $uri = image_style_path($style_name, $path);
  return file_exists($uri);
}

Assuming you have a file object you would call it like this:

$image_exists = image_style_path_exists('thumbnail', $file->uri);

If you only need to use it once in the site you could boil it down to:

$image_exists = file_exists(image_style_path('thumbnail', $file->uri));

but it's usually better to separate this sort of thing out into a function

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.