diff --git a/src/Colors/Profile.php b/src/Colors/Profile.php index b6aa0e9e..11861caf 100644 --- a/src/Colors/Profile.php +++ b/src/Colors/Profile.php @@ -17,6 +17,12 @@ class Profile extends File implements ProfileInterface */ public static function fromPath(string $path): self { - return new self(fopen($path, 'r')); + $pointer = fopen($path, 'r'); + + if ($pointer === false) { + throw new RuntimeException('Unable to read image profile from path.'); + } + + return new self($pointer); } } diff --git a/src/Drivers/Gd/Analyzers/PixelColorAnalyzer.php b/src/Drivers/Gd/Analyzers/PixelColorAnalyzer.php index 80542f3c..1213270f 100644 --- a/src/Drivers/Gd/Analyzers/PixelColorAnalyzer.php +++ b/src/Drivers/Gd/Analyzers/PixelColorAnalyzer.php @@ -8,10 +8,12 @@ use GdImage; use Intervention\Image\Analyzers\PixelColorAnalyzer as GenericPixelColorAnalyzer; use Intervention\Image\Exceptions\ColorException; use Intervention\Image\Exceptions\GeometryException; +use Intervention\Image\Exceptions\RuntimeException; use Intervention\Image\Interfaces\ColorInterface; use Intervention\Image\Interfaces\ColorspaceInterface; use Intervention\Image\Interfaces\ImageInterface; use Intervention\Image\Interfaces\SpecializedInterface; +use ValueError; class PixelColorAnalyzer extends GenericPixelColorAnalyzer implements SpecializedInterface { @@ -31,16 +33,19 @@ class PixelColorAnalyzer extends GenericPixelColorAnalyzer implements Specialize /** * @throws GeometryException * @throws ColorException + * @throws RuntimeException */ protected function colorAt(ColorspaceInterface $colorspace, GdImage $gd): ColorInterface { $index = @imagecolorat($gd, $this->x, $this->y); - if (!imageistruecolor($gd)) { - $index = imagecolorsforindex($gd, $index); + if ($index === false) { + throw new RuntimeException('Unable to read color at pixel ' . $this->x . ', ' . $this->y . '.'); } - if ($index === false) { + try { + $index = imagecolorsforindex($gd, $index); + } catch (ValueError) { throw new GeometryException( 'The specified position is not in the valid image area.' ); diff --git a/src/Drivers/Gd/FontProcessor.php b/src/Drivers/Gd/FontProcessor.php index f43a2cb8..84ac2e6a 100644 --- a/src/Drivers/Gd/FontProcessor.php +++ b/src/Drivers/Gd/FontProcessor.php @@ -5,6 +5,7 @@ declare(strict_types=1); namespace Intervention\Image\Drivers\Gd; use Intervention\Image\Drivers\AbstractFontProcessor; +use Intervention\Image\Exceptions\FontException; use Intervention\Image\Geometry\Point; use Intervention\Image\Geometry\Rectangle; use Intervention\Image\Interfaces\FontInterface; @@ -44,6 +45,10 @@ class FontProcessor extends AbstractFontProcessor string: $text ); + if ($box === false) { + throw new FontException('Unable to calculate box size of font.'); + } + // build size from points return new Rectangle( width: intval(abs($box[6] - $box[4])), // difference of upper-left-x and upper-right-x diff --git a/src/Traits/CanBuildFilePointer.php b/src/Traits/CanBuildFilePointer.php index 7c22d394..d5d7c29d 100644 --- a/src/Traits/CanBuildFilePointer.php +++ b/src/Traits/CanBuildFilePointer.php @@ -22,6 +22,11 @@ trait CanBuildFilePointer is_resource($data) && get_resource_type($data) === 'stream' => fn(mixed $data) => $data, is_string($data) => function (mixed $data) { $pointer = fopen('php://temp', 'r+'); + + if ($pointer === false) { + throw new RuntimeException('Unable to build file pointer.'); + } + fwrite($pointer, $data); return $pointer; },