Clear Image Cache Plugin

Permalink 1 user found helpful
At CityMind we have been using custom image attributes a lot recently. Image attributes are a very versatile and when combined with the image helper make the process of resizing photos uploaded by clients much easier. With some simple code you can load in an image attribute, created a thumbnail of the image in the correct size, and display the thumbnail on the page:

<?php $img = LibraryFileBlockController::getFile($c->getAttribute('image_attribute')->fID); ?>
<img src="<?php echo $img->getThumbnail(640,480)->src; ?>">


The image helper generates a thumbnail of the correct size and store it in the cache folder. When the page is loaded the thumbnail stored in the cache folder is loaded and displayed on the page. This works great assuming you never change the image attribute. But if you do change the image attribute the new image will not be visible on the page. Why? Because if a thumbnail already exist in the cache folder it will not be overwritten. So if the attribute is changed after the first thumbnail has been created a new thumbnail will never be created. This is a problem.

What concrete5 needs to do is:

1. Allow user clear the image cache manually.
2. Somehow force getThumbnail() to reevaluate the image it is getting the thumbnail of, and, if the file has changed, regenerate the thumbnail.

I decide to write a plugin to fix the first issue. It is an add-on called Clear Image Cache. You can download the attached zip file or download the files from github repository. Here is the link to the repository:https://github.com/Stratus3D/clear_image_cache/....

I would love to have this code critiqued/reviewed so feel free to comment or send me an email. I really think this functionality should be part of the core. Should I try getting this code added to the concrete5 core?

Thank you,

Trevor

1 Attachment