Skip to content

Commit

Permalink
Correção bug ao salvar imagem png com fundo transparente
Browse files Browse the repository at this point in the history
  • Loading branch information
FernandoZueet committed Jan 17, 2020
1 parent c3fa989 commit 1d4a0e9
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
10 changes: 8 additions & 2 deletions src/ImageGd/ImageGd.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,19 +130,25 @@ public function imageCreateFrom(string $mimeType, string $filename)
* Image adjustments
*
* @param resource $image
* @param string $mimeType
* @return boolean
*/
public function imageAdjustments($image = null) : bool
public function imageAdjustments($image = null, string $mimeType = '') : bool
{
if ($image == null) {
$image = $this->imageResource;
}

$blendmode = true;
if($mimeType == 'image/png') {
$blendmode = false;
}

if(!imagepalettetotruecolor($image)) {
return false;
};

if(!imagealphablending($image, true)) {
if(!imagealphablending($image, $blendmode)) {
return false;
}

Expand Down
2 changes: 1 addition & 1 deletion src/ImageGd/ResizeImage.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ public function execute() : bool
$imageDst = imagecreatetruecolor($width, $height);

//image adjustments
if (!$this->getImageGd()->imageAdjustments($imageDst)) {
if (!$this->getImageGd()->imageAdjustments($imageDst, $this->getFile()['mimeType'])) {
return false;
}

Expand Down
2 changes: 1 addition & 1 deletion src/ImageGd/WatermarksImage.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ public function execute() : bool
}

//image adjustments
if (!$this->getImageGd()->imageAdjustments($image)) {
if (!$this->getImageGd()->imageAdjustments($image, $this->getFile()['mimeType'])) {
return false;
}

Expand Down

0 comments on commit 1d4a0e9

Please sign in to comment.