I am working on a script that works similar to Rasterbator
It goes through an image pixel by pixel, gets the color and brightness then creates a larger circle for each pixel. The size of the dot is based on the brightness of the pixel. Right now it goes through the whole image, draws each circle at the right size, but for some reason it stops doing the correct color after a while. I can't figure it out. Below is the code. I am attaching a sample output image.
<?
include("image.php");
$img = imagecreatefromjpeg('small.jpg');
$maxsize = 4;
$sx = imagesx($img);
$sy = imagesy($img);
$newim = imageCreate(($sx$maxsize),($sy$maxsize));
$background = imageColorAllocate($newim, 255,255,255);
for ($x = 0; $x < $sx; $x++) {
for ($y = 0; $y < $sy; $y++) {
//gets the rgb value of the pixel and puts into an array
$rgb = Image::getPixelRGB($img, $x, $y);
//converts the rgb value to hsv
$hsv = Image::rgb2hsv($rgb);
//set color of circle
$color = imageColorAllocate($newim, $rgb[0], $rgb[1], $rgb[2]);
//set position of circle
$newx = ($x$maxsize)-($maxsize/2);
$newy = ($y$maxsize)-($maxsize/2);
//set size of circle based on brightness of pixel
$newsize = $maxsize*(1.5-($hsv[2]));
if ($newsize > $maxsize){
$newsize = $maxsize;
}
//draw circle
imageFilledEllipse($newim,$newx,$newy,$newsize,$newsize,$color);
}
}
//display image
header('Content-type: image/jpg');
imageJPEG($newim);
imageDestroy($newim);
?>