Skip to content

Commit

Permalink
Prise en charge du format WEBP
Browse files Browse the repository at this point in the history
  • Loading branch information
AnaelMobilia committed Jan 14, 2024
1 parent 6cd8e71 commit 1082e20
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 2 deletions.
27 changes: 27 additions & 0 deletions __tests/ImageObjectTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,33 @@ public function testRotationImagesGIF(): void
}
}


/**
* Rotation des images WEBP
* Pas de changement en fonction des versions de PHP
* @runInSeparateProcess
*/
public function testRotationImagesWEBP(): void
{
require 'config/config.php';
$monImage = new ImageObject();

foreach (self::VALEURS_ANGLE as $angle) {
$monImage->rotation(
$angle,
_PATH_TESTS_IMAGES_ . 'test.webp',
_PATH_TESTS_OUTPUT_ . 'test.webp-' . $angle
);
$this->assertTrue(
$this->compareImages(
_PATH_TESTS_IMAGES_ . 'test' . $angle . '.webp',
_PATH_TESTS_OUTPUT_ . 'test.webp-' . $angle
),
'Rotation WEBP ' . $angle
);
}
}

/**
* Redimensionnement des images
* @runInSeparateProcess
Expand Down
Binary file added __tests/images/test-180.webp
Binary file not shown.
Binary file added __tests/images/test-270.webp
Binary file not shown.
Binary file added __tests/images/test-90.webp
Binary file not shown.
Binary file added __tests/images/test.webp
Binary file not shown.
4 changes: 4 additions & 0 deletions classes/HelperImage.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,10 @@ public static function setImage(Imagick $uneImage, int $imageType, string $path)
$uneImage->setInterlaceScheme(Imagick::INTERLACE_PNG);
$uneImage->setImageCompression(Imagick::COMPRESSION_LZW);
$uneImage->setImageCompressionQuality(9);
} elseif ($imageType === IMAGETYPE_WEBP) {
$uneImage->setImageFormat('webp');
$uneImage->setImageCompression(Imagick::COMPRESSION_LZW);
$uneImage->setImageCompressionQuality(100);
}
// Suppression des commentaires & co
$uneImage->stripImage();
Expand Down
4 changes: 2 additions & 2 deletions config/image-heberg.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,8 @@ function exception_handler(Throwable $exception): void
define('_SIZE_PREVIEW_', 256);

// Types d'images gérés
define('_ACCEPTED_EXTENSIONS_', ['JPG', 'PNG', 'GIF']);
define('_ACCEPTED_MIME_TYPE_', [IMAGETYPE_JPEG, IMAGETYPE_PNG, IMAGETYPE_GIF]);
define('_ACCEPTED_EXTENSIONS_', ['JPG', 'PNG', 'GIF', 'WEBP']);
define('_ACCEPTED_MIME_TYPE_', [IMAGETYPE_JPEG, IMAGETYPE_PNG, IMAGETYPE_GIF, IMAGETYPE_WEBP]);

/**
* Tor
Expand Down

0 comments on commit 1082e20

Please sign in to comment.