Problem with gd library's function imageColorSet()

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Jilimay
Forum Newbie
Posts: 2
Joined: Mon Apr 18, 2011 2:56 am

Problem with gd library's function imageColorSet()

Post by Jilimay »

Hello everyone,

I am currently working on a project and I would like to be able to replace colors by other in
some pictures.

I used the following code but it just does nothing, and I have no clue why. What do I get wrong ?

Code: Select all

$imgPath = "pictures/basic.png";
$myPicture = imageCreateFromPng($imgPath);
$index = imageColorat($myPicture, 5, 5);
imagecolorset ($myPicture, $index, 255, 0, 0);
imagepng($myPicture, $imgPath);

I also uploaded the picture I am trying to modify.

Thanks for reading.
Attachments
basic.png
basic.png (6.53 KiB) Viewed 606 times
Jilimay
Forum Newbie
Posts: 2
Joined: Mon Apr 18, 2011 2:56 am

Re: Problem with gd library's function imageColorSet()

Post by Jilimay »

Hello again,

I haven't found any solution to this issue, even if I believe the trick to be related with the
picture's resolution. But I found a way to bypass the problem, by using another function : bool imagefill ( resource $image , int $x , int $y , int $color ).

It basically acts like the paint's filling function, and allow me to do what I wanted to.

Hope it will help someone else :) !
Post Reply