Skip to content

Commit

Permalink
Merge pull request #57 from romanmatyus/master
Browse files Browse the repository at this point in the history
Image::place() fixed unexpected output with transparency image #56
  • Loading branch information
dg committed Feb 24, 2015
2 parents 6da3c27 + 0e8c60c commit 29bfb44
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/Utils/Image.php
Original file line number Diff line number Diff line change
Expand Up @@ -487,8 +487,18 @@ public function place(Image $image, $left = 0, $top = 0, $opacity = 100)
);

} elseif ($opacity <> 0) {
$cutting = imagecreatetruecolor($image->getWidth(), $image->getHeight());
imagecopy(
$cutting, $this->image,
0, 0, $left, $top, $image->getWidth(), $image->getHeight()
);
imagecopy(
$cutting, $image->getImageResource(),
0, 0, 0, 0, $image->getWidth(), $image->getHeight()
);

imagecopymerge(
$this->image, $image->getImageResource(),
$this->image, $cutting,
$left, $top, 0, 0, $image->getWidth(), $image->getHeight(),
$opacity
);
Expand Down
11 changes: 11 additions & 0 deletions tests/Utils/Image.alpha1.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,17 @@ if (!extension_loaded('gd')) {
}


$rectangle = Image::fromBlank(100, 100, Image::rgb(255, 255, 255, 127));
$rectangle->filledRectangle(25, 25, 74, 74, Image::rgb(255, 0, 0, 63));

$image = Image::fromBlank(200, 100, Image::rgb(0, 255, 0));
$image->place($rectangle, 50, 0, 63);

$image2 = Image::fromBlank(200, 100, Image::rgb(0, 255, 0));
$image2->place(Image::fromBlank(50, 50, Image::rgb(80, 173, 0)), 75, 25);

Assert::same($image2->toString(Image::PNG, 0), $image->toString(Image::PNG, 0));

ob_start();

$image = Image::fromBlank(200, 100, Image::rgb(255, 128, 0, 60));
Expand Down

0 comments on commit 29bfb44

Please sign in to comment.