Файл: vendor/intervention/image/src/Drivers/Imagick/Analyzers/PixelColorAnalyzer.php
Строк: 95
<?php
declare(strict_types=1);
namespace InterventionImageDriversImagickAnalyzers;
use ImagickException;
use InterventionImageAnalyzersPixelColorAnalyzer as GenericPixelColorAnalyzer;
use InterventionImageExceptionsAnalyzerException;
use InterventionImageExceptionsInvalidArgumentException;
use InterventionImageExceptionsStateException;
use InterventionImageInterfacesColorInterface;
use InterventionImageInterfacesColorProcessorInterface;
use InterventionImageInterfacesFrameInterface;
use InterventionImageInterfacesImageInterface;
use InterventionImageInterfacesSpecializedInterface;
class PixelColorAnalyzer extends GenericPixelColorAnalyzer implements SpecializedInterface
{
/**
* @throws InvalidArgumentException
* @throws AnalyzerException
* @throws StateException
*/
public function analyze(ImageInterface $image): mixed
{
if ($this->x > $image->width() - 1 || $this->y > $image->height() - 1) {
throw new InvalidArgumentException(
'The specified position (' . $this->x . ', ' . $this->y . ') is not within the image area',
);
}
$colorProcessor = $this->driver()->colorProcessor($image);
return $this->colorAt($colorProcessor, $image->core()->frame($this->frame));
}
/**
* @throws AnalyzerException
*/
protected function colorAt(ColorProcessorInterface $processor, FrameInterface $frame): ColorInterface
{
try {
return $processor->import(
$frame->native()->getImagePixelColor($this->x, $this->y),
);
} catch (ImagickException $e) {
throw new AnalyzerException(
'Failed to read pixel color at position ' . $this->x . ', ' . $this->y,
previous: $e,
);
}
}
}