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

Asked

Viewed 42 times

0

I need help with an image. I want to know how to limit her colors to 16 colors?

Example:

Before:

inserir a descrição da imagem aqui

Afterward:

inserir a descrição da imagem aqui

  • It would be good [Dit] your question by putting an example of what you want to get, explain what you tried and what was the difficulty found so that the community can help better.

1 answer

0

In this example, you load an image, jpg or png, also loads a gif(16colors), the image you want to manipulate copies the color properties of the gif, saves a new one and erases everyone who will not be useful, see at which points Oce will interact with your images, which ones to discard and which 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). inserir a descrição da imagem aqui

$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);
?>

Browser other questions tagged

You are not signed in. Login or sign up in order to post.