Skip to content

Commit

Permalink
fix imagick load from remote url
Browse files Browse the repository at this point in the history
  • Loading branch information
sergix44 committed Jun 30, 2024
1 parent 253a288 commit 142cc39
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/Drivers/Imagick/Imagick.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ public function loadImageFrom(string $path): ImagickBackend
if (file_exists($path)) {
$imagick->readImage($path);
$imagick->setImageType(defined('\Imagick::IMGTYPE_TRUECOLORALPHA') ? \Imagick::IMGTYPE_TRUECOLORALPHA : \Imagick::IMGTYPE_TRUECOLORMATTE);
} elseif (filter_var($path, FILTER_VALIDATE_URL)) {
$imagick->readImageBlob(file_get_contents($path));
$imagick->setImageType(defined('\Imagick::IMGTYPE_TRUECOLORALPHA') ? \Imagick::IMGTYPE_TRUECOLORALPHA : \Imagick::IMGTYPE_TRUECOLORMATTE);
} else {
if ($this->isDataUriImage($path)) {
$path = $this->decodeDataUriImage($path);
Expand Down
12 changes: 12 additions & 0 deletions tests/DriverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -772,3 +772,15 @@ function (Text $text) {
->imageSimilarTo($expected, 95);
unlink($out);
})->with('drivers', 'fruit');

it('returns an http response', function ($driver, $file) {
prepare($this, '_', $driver);
$response = Image::make($file, $driver)->response();
expect($response->getStatusCode())->toBe(200);
})->with('drivers', 'tile');

it('can open a remote image', function ($driver) {
prepare($this, '_', $driver);
$image = Image::make('https://via.placeholder.com/150', $driver);
expect($image->width())->toBe(150)->and($image->height())->toBe(150);
})->with('drivers');

0 comments on commit 142cc39

Please sign in to comment.