image - Limit Color Palette using PHP -



image - Limit Color Palette using PHP -

is there way limit image custom color palette of 15 colors (plus transparency)? adjust color palette of images specific set of colors using php functions.

right loading images using imagecreatefrompng(), contain default rgb palette. have 4x4px image each desired color.

i have tried using imagepalettecopy(), doesn't seem have effect.

$palette = imagecreatefrompng(public_path() . "/assets/palette2.png"); $original = imagecreatefrompng(public_path() . '/uploads/test1.png'); $resampled = imagecreatetruecolor(5, 5); imagepalettecopy($resampled, $palette); imagecopyresampled($resampled, $original, 0, 0, 0, 0, 5, 5, imagesx($original), imagesy($original)); imagepalettecopy($resampled, $palette);

thanks!

i found next work excellently pure php. not sure how stacks performance-wise, provides desired results:

$palette = imagecreatefrompng(public_path() . "/assets/palette.png"); $original1 = imagecreatefrompng(public_path() . '/uploads/test1.png'); $resampled1 = imagecreatetruecolor(5, 5); $adjusted1 = imagecreatetruecolor(5, 5); imagetruecolortopalette($palette, false, 16); imagecopyresampled($resampled1, $original1, 0, 0, 0, 0, 5, 5, imagesx($original1), imagesy($original1)); ($row = 0; $row < 5; $row++) { ($column = 0; $column < 5; $column++) { $rgb1 = imagecolorat($resampled1, $column, $row); $color1 = imagecolorsforindex($resampled1, $rgb1); $closestrgb1 = imagecolorclosest($palette, $color1['red'], $color1['green'], $color1['blue']); $closestcolor1 = imagecolorsforindex($palette, $closestrgb1); imagesetpixel($adjusted1, $column, $row, imagecolorallocate($adjusted1, $closestcolor1['red'], $closestcolor1['green'], $closestcolor1['blue'])); } }

php image color-palette

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -