Файл: vendor/intervention/image/src/Drivers/Imagick/Modifiers/ContrastModifier.php
Строк: 75
<?php
declare(strict_types=1);
namespace InterventionImageDriversImagickModifiers;
use Imagick;
use ImagickException;
use InterventionImageExceptionsModifierException;
use InterventionImageInterfacesImageInterface;
use InterventionImageInterfacesSpecializedInterface;
use InterventionImageModifiersContrastModifier as GenericContrastModifier;
class ContrastModifier extends GenericContrastModifier implements SpecializedInterface
{
/**
* @throws ModifierException
*/
public function apply(ImageInterface $image): ImageInterface
{
// sigmoidalContrastImage's midpoint argument is in QuantumRange units,
// not the [0..1] range a normalized API would imply. Passing 0 pivots
// the sigmoidal curve around pure black, which lifts every pixel
// including the midtone — the opposite of a symmetric contrast
// adjustment. Pivot around the middle of the QuantumRange so a
// mid-grey pixel survives unchanged and the curve is symmetric.
$midpoint = Imagick::QUANTUM_RANGE / 2;
foreach ($image as $frame) {
try {
$result = $frame->native()->sigmoidalContrastImage($this->level > 0, abs($this->level / 4), $midpoint);
if ($result === false) {
throw new ModifierException(
'Failed to apply ' . self::class . ', unable to adjust image contrast',
);
}
} catch (ImagickException $e) {
throw new ModifierException(
'Failed to apply ' . self::class . ', unable to adjust image contrast',
previous: $e,
);
}
}
return $image;
}
}