Skip to content

Commit

Permalink
Image: fixed lost of alpha after imagecrop() [Closes #202]
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Oct 21, 2019
1 parent 211b159 commit 8b72022
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/Utils/Image.php
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,7 @@ public function crop($left, $top, $width, $height)
[$r['x'], $r['y'], $r['width'], $r['height']]
= static::calculateCutout($this->getWidth(), $this->getHeight(), $left, $top, $width, $height);
$this->image = imagecrop($this->image, $r);
imagesavealpha($this->image, true);
return $this;
}

Expand Down
8 changes: 8 additions & 0 deletions tests/Utils/Image.resize.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,14 @@ test(function () use ($main) { // rotate
});


test(function () use ($main) { // alpha crop
$image = Image::fromFile(__DIR__ . '/fixtures.images/alpha1.png');
$image->crop(1, 1, 8, 8);
Assert::same(file_get_contents(__DIR__ . '/expected/Image.alpha.crop.gd2'), toGd2($image));
Assert::same(file_get_contents(__DIR__ . '/expected/Image.alpha.crop.png'), $image->toString($image::PNG));
});


test(function () use ($main) { // alpha resize
$image = Image::fromFile(__DIR__ . '/fixtures.images/alpha1.png');
$image->resize(20, 20);
Expand Down
Binary file added tests/Utils/expected/Image.alpha.crop.gd2
Binary file not shown.
Binary file added tests/Utils/expected/Image.alpha.crop.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 8b72022

Please sign in to comment.