I need help how do I limit or balance the colors of an image with php

0

I need help with an image. I want to know how do I limit the colors of it type 16 colors?

Example:

Before:

Then:

    
asked by anonymous 08.11.2017 / 21:23

1 answer

0

In this example, you load an image, jpg or png, also loads a gif (16cores), the image you want to manipulate copies the color properties of the gif, saves a new one and erases everyone that will be of no use, see in which points you will interact with your images, which ones to discard and which ones to keep saved. The color gif is attached here. You can still choose to save your new image in png or jpg (if the idea is to reduce allocation this is lighter).     

$palette = imagecreatefromgif('palette-gif-03.gif');

$source = imagecreatefromjpeg('test-image-01.jpg');

$source_w = imagesx($source);
$source_h = imagesy($source);

$image = imagecreate($source_w, $source_h);

imagepalettecopy($image, $palette);

imagecopy($image, $source, 0, 0, 0, 0, $source_w, $source_h);

header('Content-Type: image/png');
imagepng($image);

imagedestroy($imgage);
imagedestroy($palette);
imagedestroy($source);
?>
    
09.11.2017 / 00:00