Файл: vendor/intervention/image/src/Drivers/Gd/Analyzers/PixelColorAnalyzer.php
Строк: 106
<?php
declare(strict_types=1);
namespace InterventionImageDriversGdAnalyzers;
use InterventionImageAnalyzersPixelColorAnalyzer as GenericPixelColorAnalyzer;
use InterventionImageExceptionsAnalyzerException;
use InterventionImageExceptionsInvalidArgumentException;
use InterventionImageExceptionsStateException;
use InterventionImageInterfacesColorInterface;
use InterventionImageInterfacesColorProcessorInterface;
use InterventionImageInterfacesFrameInterface;
use InterventionImageInterfacesImageInterface;
use InterventionImageInterfacesSpecializedInterface;
use ValueError;
class PixelColorAnalyzer extends GenericPixelColorAnalyzer implements SpecializedInterface
{
/**
* {@inheritdoc}
*
* @see AnalyzerInterface::analyze()
*
* @throws InvalidArgumentException
* @throws AnalyzerException
* @throws StateException
*/
public function analyze(ImageInterface $image): mixed
{
$colorProcessor = $this->driver()->colorProcessor($image);
return $this->colorAt($colorProcessor, $image->core()->frame($this->frame));
}
/**
* @throws InvalidArgumentException
* @throws AnalyzerException
*/
protected function colorAt(ColorProcessorInterface $processor, FrameInterface $frame): ColorInterface
{
$gd = $frame->native();
$index = @imagecolorat($gd, $this->x, $this->y);
if (!is_int($index)) {
throw new InvalidArgumentException(
'The specified position (' . $this->x . ', ' . $this->y . ') is not within the image area',
);
}
try {
$colors = imagecolorsforindex($gd, $index);
} catch (ValueError) {
throw new AnalyzerException(
'The specified index is outside of the range',
);
}
return $processor->import($colors);
}
}