udjamaflip
05-11-2008, 12:33 PM
I have already made this short function:
function fetch_palette($img)
{
$imgDetails = getimagesize($img);
$x = 1;
$y = 1;
while ($y <= intval($imgDetails[1]))
{
while ($x <= intval($imgDetails[0]))
{
$color = imagecolorat(imagecreatefromjpeg($img), $x, $y);
if ($colors[$color])
{
$tmp = $colors[$color];
$tmp = intval($tmp);
$colors[$color] = $tmp;
}
else
{
$colors[$color] = 1;
}
$x++;
}
$x = 1;
$y++;
}
return $colors;
}
but as you can tell, running this on an image thats bigger than 50x50 and it starts really messing with the server, and over 300x300 it will actually timeout due to it taking over 60 seconds to load.
Is there something I can do to make it more efficient, or is there a "get_palette" already existing in PHP?
The overall purpose is that I find the most popular used colours in the image palette.
function fetch_palette($img)
{
$imgDetails = getimagesize($img);
$x = 1;
$y = 1;
while ($y <= intval($imgDetails[1]))
{
while ($x <= intval($imgDetails[0]))
{
$color = imagecolorat(imagecreatefromjpeg($img), $x, $y);
if ($colors[$color])
{
$tmp = $colors[$color];
$tmp = intval($tmp);
$colors[$color] = $tmp;
}
else
{
$colors[$color] = 1;
}
$x++;
}
$x = 1;
$y++;
}
return $colors;
}
but as you can tell, running this on an image thats bigger than 50x50 and it starts really messing with the server, and over 300x300 it will actually timeout due to it taking over 60 seconds to load.
Is there something I can do to make it more efficient, or is there a "get_palette" already existing in PHP?
The overall purpose is that I find the most popular used colours in the image palette.