Файл: vendor/intervention/image/src/Drivers/Imagick/Modifiers/StripMetaModifier.php
Строк: 68
<?php
declare(strict_types=1);
namespace InterventionImageDriversImagickModifiers;
use ImagickException;
use InterventionImageCollection;
use InterventionImageExceptionsModifierException;
use InterventionImageInterfacesImageInterface;
use InterventionImageInterfacesModifierInterface;
use InterventionImageInterfacesSpecializedInterface;
class StripMetaModifier implements ModifierInterface, SpecializedInterface
{
/**
* {@inheritdoc}
*
* @see InterventionImageInterfacesModifierInterface::apply()
*
* @throws ModifierException
*/
public function apply(ImageInterface $image): ImageInterface
{
// preserve icc profiles
try {
$profiles = $image->core()->native()->getImageProfiles('icc');
} catch (ImagickException $e) {
throw new ModifierException(
'Failed to apply ' . self::class . ', unable to preserve icc profiles',
previous: $e,
);
}
// remove meta data
try {
$result = $image->core()->native()->stripImage();
if ($result === false) {
throw new ModifierException(
'Failed to apply ' . self::class . ', unable to strip meta data',
);
}
} catch (ImagickException $e) {
throw new ModifierException(
'Failed to apply ' . self::class . ', unable to strip meta data',
previous: $e,
);
}
$image->setExif(new Collection());
if ($profiles !== []) {
// re-apply icc profiles
try {
$result = $image->core()->native()->profileImage("icc", $profiles['icc']);
if ($result === false) {
throw new ModifierException(
'Failed to apply ' . self::class . ', unable to re-apply icc profile',
);
}
} catch (ImagickException $e) {
throw new ModifierException(
'Failed to apply ' . self::class . ', unable to re-apply icc profile',
previous: $e,
);
}
}
return $image;
}
}