exif_removal
EXIF Removal is a privacy-focused Drupal module that automatically strips sensitive metadata from uploaded images. It protects user privacy by removing GPS locations, device information, and timestamps that could potentially expose personal information.
The module works silently in the background during the file upload process. When users upload images through any Drupal form (content creation, user pictures, media library, etc.), the module intercepts the upload, processes the image to remove sensitive metadata, and then allows the upload to complete normally.
It uses GD and imagejpeg() to create a new copy of the image, imagejpeg() will reencode the image, we use the quality value 80 because the comment from PHP page https://www.php.net/manual/en/function.imagejpeg.php#76780
I did an experiment with the image quality parameter of the imagejpeg() function when creating jpegs. I found the optimal image quality with file size is taken into account to be 80 - very close to the default value of 75.
Anything over 80 results in an unnecessary increase in file size without much increase in image quality.
// Remove all EXIF data from the image.
if ($file->getMimeType() == 'image/jpeg') {
// Use GD to strip all EXIF data by re-saving the image.
$image_resource = @imagecreatefromjpeg($path);
if (!$image_resource) {
// Failed to create image resource.
return FALSE;
}
// Create a new image without EXIF data.
imagejpeg($image_resource, $path, 80);
imagedestroy($image_resource);
return TRUE;
}
It also supports imagemagick if image_effects is installed.
$image = $this->imageFactory->get($file->getFileUri());
if ($this->moduleHandler->moduleExists('image_effects')
&& $image->getToolkit()->getPluginId() == 'imagemagick') {
$toolkit = $image->getToolkit();
if ($toolkit->apply('strip')) {
$image->save();
}
}