gpt4 book ai didi

php - 用颜色覆盖 png 图像 (php)

转载 作者:行者123 更新时间:2023-12-03 07:13:47 24 4
gpt4 key购买 nike

我有一张这样的图片

enter image description here


我需要像这样上床

enter image description here

我还需要保持透明的边缘。

最佳答案

您可以使用 ImageMagick 中的阈值函数将所有颜色变为黑色,如下所示:

<?php
// Load the PNG image
$im = new Imagick("image.png");

// Make everything black
$im->thresholdimage(65536);
$im->writeImage("result.png");
?>

enter image description here

如果您使用超过 16 位的每 channel 量化,那么这样做可能更合适:

#!/usr/local/bin/php -f

<?php
// Load the PNG image
$im = new Imagick("image.png");

// Work out quantum range - probably 255 or 65535
$m=$im->getQuantumRange();
$m=$m["quantumRangeLong"];

// Make everything darker than that black
$im->thresholdimage($m);
$im->writeImage("result.png");
?>

关于php - 用颜色覆盖 png 图像 (php),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33517308/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com