Skip to content

Commit 7fb60f9

Browse files
flatten background while convert transparent image
1 parent 322d654 commit 7fb60f9

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

src/Utility/Image.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ public function resize(string $disk, string $sourceFile, string $targetFile, int
1919
Storage::disk($disk)->get($sourceFile)
2020
);
2121

22+
if ($image->hasAlpha()) {
23+
$image = $image->flatten(['background' => [255, 255, 255]]);
24+
}
25+
2226
$width = min($image->width, $width);
2327
$height = min($image->height, $height);
2428
$ext = pathinfo($targetFile, PATHINFO_EXTENSION);
@@ -45,6 +49,10 @@ public function convert(string $disk, string $sourceFile, string $targetFile): v
4549
Storage::disk($disk)->get($sourceFile)
4650
);
4751

52+
if ($image->hasAlpha()) {
53+
$image = $image->flatten(['background' => [255, 255, 255]]);
54+
}
55+
4856
$ext = pathinfo($targetFile, PATHINFO_EXTENSION);
4957

5058
$saved = Storage::disk($disk)->put(

0 commit comments

Comments
 (0)