Answer the question
In order to leave comments, you need to log in
How to convert an image to another one with only certain colors?
$img = imagecreatetruecolor($width,$height);
// Задаю палитру для нового изображения. Ожидаю, что полученная картинка будет состоять только из трех этих цветов.
imageColorAllocate($img, 255, 255, 255);
imageColorAllocate($img, 0, 0, 0);
imageColorAllocate($img, 128, 128, 128);
// Создаю изображение из исходного
$img2 = imageCreateFromJpeg($filename);
// Объединяю исходное изображение и изображение на основе трех цветов.
imageCopyMerge($img, $img2, 0, 0, 0, 0, $width, $height, 100);
Answer the question
In order to leave comments, you need to log in
Yes. If you save in JPEG, then he will throw a pig at you. Tk works not with a discrete but with a continuous (sine-cosine) representation of small fragments of the picture.
Realistically, you need a guarantee that the destination will always be in GIF/PNG formats, since they are the only ones that guarantee the exact color match at the input and output.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question