Skip to content

Commit

Permalink
Fix SVG files loosing transparency during conversion (#3728)
Browse files Browse the repository at this point in the history
* Fix SVG files loosing transparency during conversion

* Update SvgTest to allow png format

* Test that SVG conversion maintain transparency

* Allow SvgTest to be run locally
  • Loading branch information
nicolasbeauvais authored Dec 9, 2024
1 parent 4104ba3 commit fe3f17e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
9 changes: 5 additions & 4 deletions src/Conversions/ImageGenerators/Svg.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@ class Svg extends ImageGenerator
{
public function convert(string $file, ?Conversion $conversion = null): string
{
$imageFile = pathinfo($file, PATHINFO_DIRNAME).'/'.pathinfo($file, PATHINFO_FILENAME).'.jpg';
$imageFile = pathinfo($file, PATHINFO_DIRNAME).'/'.pathinfo($file, PATHINFO_FILENAME).'.png';

$image = new Imagick;
$image->readImage($file);
$image = new Imagick();
$image->setBackgroundColor(new ImagickPixel('none'));
$image->setImageFormat('jpg');
$image->readImage($file);

$image->setImageFormat('png32');

file_put_contents($imageFile, $image);

Expand Down
6 changes: 4 additions & 2 deletions tests/Conversions/ImageGenerators/SvgTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,7 @@

$imageFile = $imageGenerator->convert($media->getPath());

expect(mime_content_type($imageFile))->toEqual('image/jpeg');
})->skipWhenRunningLocally();
expect(mime_content_type($imageFile))->toEqual('image/png');

expect((new Imagick($imageFile))->getImageAlphaChannel())->toBeTrue();
});

0 comments on commit fe3f17e

Please sign in to comment.