且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

使用PHP或Javascript为Zebra打印机将RGB图像转换为Floyd-Steinberg图像

更新时间:2023-11-09 13:36:22

Have a look at this library GDIndexedColorConverter that's a simple library that convert an image into indexed color mode.

require 'GDIndexedColorConverter.php';

// create an image
$image = imagecreatefromjpeg('image.jpg');

// create a gd indexed color converter
$converter = new GDIndexedColorConverter();

// the color palette
$palette = array(
    array(0, 0, 0),
    array(255, 255, 255),
    array(0, 0, 0),
    array(0, 0, 0),
    array(0, 0, 0)
);

// convert the image to indexed color mode
$new_image = $converter->convertToIndexedColor($image, $palette, 0.25);

// save the new image
imagepng($new_image, 'example_indexed_color.png', 0);

Here is the input:

And here is the output: