Strip photo metadata with GD (Imagick keeps EXIF), --force option, stricter test

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Lars StommerandClaude Opus 5.5 committed 2026-10-22 21:43:54 +02:00
1 parent 4f69b426a4
commit 6690beafe6
4 files changed
+16 -7

No files matched your search

+5 -3
View File
@@ -2,6 +2,7 @@
namespace App\Support;
use Spatie\Image\Enums\ImageDriver;
use Spatie\Image\Image;
use Spatie\MediaLibrary\MediaCollections\Models\Media;
use Throwable;
@@ -14,9 +15,9 @@ class StripImageMetadata
{
private const TYPES = ['image/jpeg', 'image/png', 'image/webp'];
public static function strip(Media $media): bool
public static function strip(Media $media, bool $force = false): bool
{
if (! in_array($media->mime_type, self::TYPES, true) || $media->getCustomProperty('metadata_stripped')) {
if (! in_array($media->mime_type, self::TYPES, true) || ($media->getCustomProperty('metadata_stripped') && ! $force)) {
return false;
}
@@ -26,7 +27,8 @@ public static function strip(Media $media): bool
}
try {
Image::load($path)->quality(90)->save($path);
// GD on purpose: Imagick (default when installed, e.g. on Strato) keeps the EXIF data when saving.
Image::useImageDriver(ImageDriver::Gd)->loadFile($path)->quality(90)->save($path);
} catch (Throwable $exception) {
report($exception);