Skip to content

Commit 8bdf76f

Browse files
committed
wip
1 parent 4b04f2c commit 8bdf76f

2 files changed

Lines changed: 22 additions & 20 deletions

File tree

system/Images/Handlers/ImageMagickHandler.php

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,22 @@ protected function _flip(string $direction)
277277
return $this;
278278
}
279279

280+
/**
281+
* Changes the image type.
282+
*
283+
* Validates that the target format is supported before applying the change.
284+
*
285+
* @throws ImageException
286+
*/
287+
public function convert(int $imageType)
288+
{
289+
parent::convert($imageType);
290+
291+
$this->supportedFormatCheck();
292+
293+
return $this;
294+
}
295+
280296
/**
281297
* Get a driver version
282298
*
@@ -384,20 +400,6 @@ public function save(?string $target = null, int $quality = 90): bool
384400
try {
385401
$result = $this->resource->writeImage($target);
386402

387-
if (! $result || ! file_exists($target) || filesize($target) === 0) {
388-
$extension = strtoupper(pathinfo($target, PATHINFO_EXTENSION));
389-
$message = match ($extension) {
390-
'GIF' => lang('Images.gifNotSupported'),
391-
'JPG', 'JPEG' => lang('Images.jpgNotSupported'),
392-
'PNG' => lang('Images.pngNotSupported'),
393-
'WEBP' => lang('Images.webpNotSupported'),
394-
'AVIF' => lang('Images.avifNotSupported'),
395-
default => null,
396-
};
397-
398-
throw ImageException::forInvalidImageCreate($message);
399-
}
400-
401403
chmod($target, $this->filePermissions);
402404

403405
$this->resource->clear();

tests/system/Images/ImageMagickHandlerTest.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -434,14 +434,14 @@ public function testImageConvertPngToWebp(): void
434434

435435
public function testImageConvertPngToAvif(): void
436436
{
437-
try {
438-
$this->handler->withFile($this->origin . 'ci-logo.png');
439-
$this->handler->convert(IMAGETYPE_AVIF);
440-
$this->handler->save($this->root . 'ci-logo.avif');
441-
} catch (ImageException $e) {
442-
$this->markTestSkipped('AVIF encoding is not supported on this system: ' . $e->getMessage());
437+
if (! in_array('AVIF', Imagick::queryFormats(), true)) {
438+
$this->expectException(ImageException::class);
439+
$this->expectExceptionMessage('Your server does not support the GD function required to process an avif image.');
443440
}
444441

442+
$this->handler->withFile($this->origin . 'ci-logo.png');
443+
$this->handler->convert(IMAGETYPE_AVIF);
444+
$this->handler->save($this->root . 'ci-logo.avif');
445445
$this->assertSame(IMAGETYPE_AVIF, exif_imagetype($this->root . 'ci-logo.avif'));
446446
}
447447

0 commit comments

Comments
 (0)