php美顏滤镜,PHP GIF / PNG True Colorize滤镜,可保留亮度和Alpha

我一直在研究脚本一段时间,以更改GIF和PNG文件的颜色,该颜色比不保留发光度的PHP colorize滤镜更好.我想出了这个办法,但效果不佳:

$filename = "images/sprites/".$_GET['sprite'].".png";

$im = imagecreatefrompng($filename);

$nim = imagecreate( imagesx($im), imagesy($im) );

$background = imagecolorallocate($nim, 255, 0, 255);

$size = getimagesize($filename);

for($y = 0; $y < imagesy($nim); $y++) {

for($x = 0; $x < imagesx($nim); $x++) {

$rgb = imagecolorat($im, $x, $y);

$colors = imagecolorsforindex($im, $rgb);

$mods = explode("x",$_GET['color']);

$colors['red'] = ($colors['red'] / 8 + (255 - ((255 - $mods[0] - $colors['red']) * 2))) / 2;

$colors['green'] = ($colors['red'] / 8 + (255 - ((255 - $mods[1] - $colors['green']) * 2))) / 2;

$colors['blue'] = ($colors['red'] / 8 + (255 - ((255 - $mods[2] - $colors['blue']) * 2))) / 2;

$r = $colors['red'];

$g = $colors['green'];

$b = $colors['blue'];

if($r < 0) $r = 0;

if($g < 0) $g = 0;

if($b < 0) $b = 0;

if($r > 255) $r = 255;

if($g > 255) $g = 255;

if($b > 255) $b = 255;

if(!isset($color[$r.$g.$b])) {

$color[$r.$g.$b] = imagecolorallocate($nim, $r, $g, $b);

}

imagesetpixel($nim, $x, $y, $color[$r.$g.$b]);

}

}

imagecolortransparent($nim, 1);

header('Content-Type: image/png');

imagepng($nim);

解决方法:

听起来像您想要有色的灰度.这支持透明度…

标签:colors,gd,php

来源: https://codeday.me/bug/20191209/2095362.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值