Rectangle opacity after $img->fit
I have strange opacity bug after appling fit() function to the image:
$img = Image::make(Storage::get($savePath . 'background_original.jpg'));
$img->fit($puzzleImage->width, $puzzleImage->height);
$img->rectangle($x - $s, $y - $s, $x + $s, $y + $s, function ($draw) {
$draw->background('rgba(0, 0, 0, 0.5)');
});
Storage::put($savePath . "/background_resized.jpg", (string) $img->encode('jpg', 92));
//$img = Image::make(Storage::get($savePath . 'background_resized.jpg'));
$img->rectangle(100, 100, 200, 200, function ($draw) {
$draw->background('rgba(0, 0, 0, 0.5)');
});
Storage::put($savePath . "/background.jpg", (string) $img->encode('jpg', 92));
in this code I have black square instead of translucent. But if i uncomment //$img = Image::make(Storage::get($savePath . 'background_resized.jpg')); (or comment $img->fit ) the result is ok.
Also it begin work fine if I draw text with ttf font before drawing rectangle. May be in some other cases too.
Using php 7.2.7 with GD bundled (2.1.0 compatible) intervention/image version: 2.5.1
I'm having this issue as well. PHP 7.4, linux, intervention/image version: 2.5.1.
I found a temporary fix. If you create a new canvas with a transparent background color then insert it to your existing image, it works.
$img->fit($puzzleImage->width, $puzzleImage->height);
$overlay = Image::canvas(100, 100, 'rgba(0, 0, 0, 0.5)');
$img->insert($overlay, 'bottom');
This issue has been resolved as of version 3.2.