thephpleague / glide

Wonderfully easy on-demand image manipulation library with an HTTP based API.
http://glide.thephpleague.com
MIT License
2.55k stars 198 forks source link

How to Delete All Images After Switching Driver from GD to Imagick #302

Closed xpersonas closed 3 years ago

xpersonas commented 3 years ago

I have seen this on deleting single files from cache:
https://glide.thephpleague.com/1.0/config/source-and-cache/#deleting-cached-images

However, I have thousands of images in place. I switched from GD to Imagick because of weird artifacts in png files. I'm trying to determine my best course of action to get those regenerated.

Is there a directory I can delete? A command I can run?

I'm using Laravel and I have this...

$server = ServerFactory::create([
    'response' => new LaravelResponseFactory(app('request')),
    'source' => $filesystem->getDriver(),
    'cache' => $filesystem->getDriver(),
    'cache_path_prefix' => '.cache',
    'driver' => 'imagick',
    'base_url' => 'img',
    'max_image_size' => 2000*2000,
]);
tgalopin commented 3 years ago

My initial instinct would be to remove all the files of the filesystem, but I guess that's not feasible as you use the same Flysystem instance for cache and sources?

xpersonas commented 3 years ago

Yeah I copied that configuration initially from the website. I might need to revisit that. This is my first time with a Laravel site. So I'm not sure I understand how the source and the cache are the same. I wouldn't know where to begin to manually delete the cache. But that's just my ignorance.

tgalopin commented 3 years ago

The idea of source and cache filesystems is to implement a caching mechanism to avoid computing images again. Image computation is CPU intensive, if we can avoid it we should.

The way it works is thus that when Glide receives a request, 1/ first it tries to find a cached image in the cache filesystem for the request, and serve it if it exists, or 2/ generates the image, stores it in cache and serves it if it didn't exist in cache.

This means the source and cache filesystems can be two completely different filesystems. I would actually recommend you to have two different instances to avoid mixing source files with cache files. Doing so would have helped in your situation, for instance. To have two Filesystem instances, you can instanciate two instances on different directories for instance (not sure how it works in Laravel).

In your case, I'm not sure how to proceed. The easiest way to move forward would be to configure a new instance of the cache filesystem with a new directory, as that would basically clear the cache (Glide wouldn't find any cached file). But then, you may have files mixed up in the source filesystem. That's not related to Glide though, it's dependant on your situation.

xpersonas commented 3 years ago

Thank you for the thorough explanation. I was able to get my images re-generated.