gpt4 book ai didi

php - 使用 PHP 的 GD 库进行乘法过滤

转载 作者:可可西里 更新时间:2023-11-01 13:34:52 24 4
gpt4 key购买 nike

我已经尝试使用 GD 库来模拟 Photoshop 的多重效果,但我还没有找到可行的解决方案。

根据 Wikipedia ,乘法混合模式:

[...] multiplies the numbers for each pixel of the top layer with the corresponding pixel for the bottom layer. The result is a darker picture.

有谁知道使用 PHP 实现此目的的方法吗?任何帮助将不胜感激。

最佳答案

您需要获取图像的每个像素,然后将每个 RGB 值乘以背景颜色/255(这是 Photoshop 公式)。例如,带有红色背景颜色乘法滤镜的 JPG 文件,另存为 PNG 文件以获得更好的效果:

<?php 
$filter_r=216;
$filter_g=0;
$filter_b=26;
$suffixe="_red";
$path=YOURPATHFILE;

if(is_file($path)){
$image=@imagecreatefromjpeg($path);
$new_path=substr($path,0,strlen($path)-4).$suffixe.".png";

$imagex = imagesx($image);
$imagey = imagesy($image);
for ($x = 0; $x <$imagex; ++$x) {
for ($y = 0; $y <$imagey; ++$y) {
$rgb = imagecolorat($image, $x, $y);
$TabColors=imagecolorsforindex ( $image , $rgb );
$color_r=floor($TabColors['red']*$filter_r/255);
$color_g=floor($TabColors['green']*$filter_g/255);
$color_b=floor($TabColors['blue']*$filter_b/255);
$newcol = imagecolorallocate($image, $color_r,$color_g,$color_b);
imagesetpixel($image, $x, $y, $newcol);
}
}

imagepng($image,$new_path);
}
?>

关于php - 使用 PHP 的 GD 库进行乘法过滤,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15554414/

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