image icon indicating copy to clipboard operation
image copied to clipboard

Rectangle opacity after $img->fit

Open FragsterAt opened this issue 6 years ago • 3 comments

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.

FragsterAt avatar Dec 18 '19 15:12 FragsterAt

Using php 7.2.7 with GD bundled (2.1.0 compatible) intervention/image version: 2.5.1

FragsterAt avatar Dec 18 '19 15:12 FragsterAt

I'm having this issue as well. PHP 7.4, linux, intervention/image version: 2.5.1.

westy92 avatar May 25 '21 05:05 westy92

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');

westy92 avatar May 25 '21 05:05 westy92

This issue has been resolved as of version 3.2.

olivervogel avatar Dec 27 '23 08:12 olivervogel