Given the image of the file, what's the best way to convert it to an old school of 16 colors? that is, white, orange, purple, cyan, yellow, lime, pink, gray, light gray, cyan, violet, blue, brown, green, red, and black.
I made a small 1x16 image containing all 16 of these colors that I can use as the original palette (right?), But I had problems using it. It seems that imagepalettecopy() is what I want (take the 16-pixel color palette of the images and copy it to the new image), but the code I came up with does not work:
<?php $palette = imagecreatefrompng( __DIR__ . '/palette.png' ); $source = imagecreatefromjpeg( __DIR__ . '/testimage.jpg' ); $source_w = imagesx( $source ); $source_h = imagesy( $source ); $image = imagecreate( $source_w, $source_h ); imagepalettecopy( $palette, $image ); imagecopy( $image, $source, 0, 0, 0, 0, $source_w, $source_h ); header('Content-Type: image/png'); imagepng( $image );
It seems he just converts it into 16 colors, which he chooses or something (I'm not quite sure).
What am I missing or is something wrong?
EDIT: My call to imagepalettecopy() reverse, but the fix does not help. See comments below.