I am trying to use GD in PHP to reduce an image to a fixed 60 color palette. (I am aware that the results will look poor, it's a small part of a program I'm writing to identify visually similar or duplicate images)
I have a 8x8 60 color png of my palette, here:
and a test image (color gradient) here:
Test Image http://6bf4752d2ea1006477e8-3cbc1620ffd57ce5e34c93b52b8ad439.r9.cf2.rackcdn.com/test2.png
I'm running it through the following code, which should, as far as I understand, result in a version of test2.png that has been converted to my palette:
$palette = imagecreatefrompng("palette.png");
$source = imagecreatefrompng("test2.png");
$source_w = imagesx($source);
$source_h = imagesy($source);
$result = imagecreate($source_w, $source_h);
imagepalettecopy($result, $palette);
imagecopy($result, $source, 0, 0, 0, 0, $source_w, $source_h);
header('Content-type: image/gif');
imagegif($result);
Instead, the results seem to look like this:
Result http://6bf4752d2ea1006477e8-3cbc1620ffd57ce5e34c93b52b8ad439.r9.cf2.rackcdn.com/result.gif
Does anyone know why I'm getting more than 60 colors, and how to fix the issue?