What I want to do is to transform an image into a mosaico
, where each pixel
or group pixels
of the image would be replaced by a photo of a flower of similar color. That is, transform any image into a mosaico
of flowers.
I already have all the logic planned, but the only question I have is how do I insert the photo of the flower in imagem
.
What my código
does currently is to replace every pixel
with another in a shade of gray. What I want now is to replace this pixel
with a imagem
.
<?
$img = imagecreatefrompng('imagens/monalisa.png');
$largura = imagesx($img);
$altura = imagesy($img);
$c = 0;
$imagem = array();
$gd = imagecreatetruecolor($largura, $altura);
for ($j = 0; $j < $altura; $j++) {
for ($i = 0; $i < $largura; $i++) {
$rgb = imagecolorat($img, $i, $j);
$rgb = imagecolorsforindex($img, $rgb);
$escala = $rgb['red'] + $rgb['green'] + $rgb['blue'];
$nc = round($escala/3);
$cor = imagecolorallocate($gd, $nc, $nc, $nc);
imagesetpixel($gd, $i,$j, $cor);
}
}
header('Content-Type: image/png');
imagepng($gd);
?>