I'm nidhin
I'm nidhin

Reputation: 2662

imagefill() turns rest of the area black

I'm using imagefill() for changing the background color if an image.But while doing so the other areas which are not to be affected, change its color to black.

$image = imagecreatefrompng("sample.png");
$background = imagecolorallocate($image, 255, 0,0);
imagefill($image, 0,0, $background);
header("content-type: image/png");
imagepng($image,"sample.png");

This is my code.Can anyone tell me how this is happening ?

Upvotes: 2

Views: 773

Answers (2)

Saurabh Chandra Patel
Saurabh Chandra Patel

Reputation: 13586

Try this code ref

$color = imagecolorallocate($im, 255, 0, 0);
imagefill($im, 0, 0, $color );

Upvotes: 0

Musa
Musa

Reputation: 97672

Try setting the blending mode and saving the alpha

imagealphablending($image, false);
imagesavealpha($image, true);

http://www.php.net/manual/en/function.imagealphablending.php
http://www.php.net/manual/en/function.imagesavealpha.php

Upvotes: 1

Related Questions