如何使用Imagick php生成带有调色板偏移的bmp文件

发布于 2024-08-19 18:24:10 字数 491 浏览 6 评论 0原文

我正在尝试通过 php 使用 Imagick 从 jpg 生成 8 位 bmp。但我希望像素颜色从索引 16 而不是 0 开始。下面的代码显示了如何以我需要的正确格式生成 bmp,但调色板索引默认为 0。有没有办法确保调色板开始在另一个索引?

$average = new Imagick( "icon.jpg" );
$average->setCompression(Imagick::COMPRESSION_NO);
$average->quantizeImage( 32, Imagick::COLORSPACE_RGB, 0, false, false );
imagecolorset ($average, 0, 255, 255, 255);
$average->setImageFormat( "bmp" );

header( "Content-Type: image/bmp" );
echo $average;

$average->clear();
$average->destroy();

I'm trying to use Imagick via php to generate a 8bit bmp from jpg. But i would like the pixel colors to start at index 16 rather than 0. The code below shows how to generate the bmp in the correct format i need, but the palette index defaults to 0. Is there a way to make sure the palette start at another index?

$average = new Imagick( "icon.jpg" );
$average->setCompression(Imagick::COMPRESSION_NO);
$average->quantizeImage( 32, Imagick::COLORSPACE_RGB, 0, false, false );
imagecolorset ($average, 0, 255, 255, 255);
$average->setImageFormat( "bmp" );

header( "Content-Type: image/bmp" );
echo $average;

$average->clear();
$average->destroy();

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

冷血 2024-08-26 18:24:10

我不认为 Imagick 有任何内置的东西,所以你必须创建一个新的调色板(从旧调色板复制颜色并带有偏移量),然后使用 $pixel = $average::getImagePixelColor()< /code> 然后根据新调色板执行 $pixel->getColor()$pixel->setColor()

I don't think Imagick has anything built in for it, so you would have to create a new palette (copy colors from the old one with an offset) and then use $pixel = $average::getImagePixelColor() and then do $pixel->getColor() and $pixel->setColor() according to the new palette.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文