What I'm trying to do is pixelate an image of a url, add another image to it and finally save that image.
I have obtained this internet code to pixelate images but I think it does not work correctly. It does not show me the pixelated image nor does it save it. It just keeps the screen black.
<?php
$pixel = 15;
$getImagen = 'https://ep00.epimg.net/elpais/imagenes/2017/06/05/album/1496652756_562670_1496654035_album_normal.jpg';
$imagen = imagecreatefromjpeg($getImagen);
if(!$imagen) exit('ERROR');
list($ancho,$alto)=getimagesize($getImagen);
$superficieTotal = $ancho*$alto;
//
$superficieRecorrida = 0;
$auxX=0;
$auxY=0;
while($superficieRecorrida <= $superficieTotal){
$posX=0;$posY=0;$data = array();
while($posX <= $pixel and (($auxX + $posX) < $ancho)){
$posY=0;
while($posY <= $pixel and (($auxY + $posY) < $alto)){
$rgb = imagecolorat($imagen, ($auxX + $posX), ($auxY + $posY));
$r = ($rgb >> 16) & 0xFF;
$g = ($rgb >> 8) & 0xFF;
$b = $rgb & 0xFF;
$data[] = array($r,$g,$b);
$posY++;
}
$posX++;
}
// Busco promedio
$r = 0; $g = 0; $b = 0;
foreach($data as $d){
$r+= $d[0];
$g+= $d[1];
$b+= $d[2];
}
$totalArray = count($data);
if($totalArray == 0) $totalArray = 1;
$r = $r/$totalArray;
$g = $g/$totalArray;
$b = $b/$totalArray;
$colorPromedio = imagecolorallocate($imagen, $r, $g, $b);
imagefilledrectangle($imagen, $auxX, $auxY, ($auxX + $pixel), ($auxY + $pixel), $colorPromedio);
//
$auxX+= $pixel;
if($auxX >= $ancho){
$auxX = 0;
$auxY+= ($pixel+1);
}
$superficieRecorrida+= $pixel*$pixel;
}
//
Header("Content-type: image/jpeg");
imagejpeg($imagen);
imagedestroy($imagen);
Thank you for your future responses. a greeting.