This example shows how to replace color of an image in php gd.
This example shows how to replace color of an image in php gd.<?php
$image
= "images.jpg";$data
= getimagesize($image);$width
= intval($data[0]);$height
= intval($data[1]);$cloneH
= 0;$hex
= "FF0000";$oldhex
= "FCFF00";$im
= imagecreatefromJPEG($image);$color
=imagecolorallocate(
$im,hexdec(substr($hex,0,2)),hexdec(substr($hex,2,2)),hexdec(substr($hex,4,6)));for
($cloneH=0;$cloneH<$height;$cloneH++){
for($x=0;$x<$width;$x++){
imagesetpixel(
$im, $x, $cloneH, $color);}
}
header(
"Content-Type: {$data['mime']}");imageJPEG(
$im);function
colormatch($image,$x,$y,$hex){
$r2 = hexdec(substr($hex,0,2));
}
?>
After running the program you will get the following output