使用PHP GD图像库上色和交换颜色? [英] Colorizing and swapping colors with PHP GD Image Library?

查看:220
本文介绍了使用PHP GD图像库上色和交换颜色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我正在尝试使用PHP的GD图像库对图像进行着色和交换颜色.

Hello I am in the process of trying to colorize and swap colors on an image using GD image library with PHP.

我正在使用位于此处的原始图像: http://korlon.com/youknowbetter/test.jpg

I am using an original image located here: http://korlon.com/youknowbetter/test.jpg

并希望使它变成橙色的面孔,黑色的衣服和头发像您在这里看到的那样: http://youknowdifferent.org/

And wish to get it to a point where it is orange face with black clothes and hair much like you see here: http://youknowdifferent.org/

到目前为止,我已经使用以下代码:

So far I've used the following code:

<?php
header('Content-type: image/jpeg');
$im = imagecreatefromjpeg('test.jpg');



imagefilter($im, IMG_FILTER_GRAYSCALE);
imagefilter($im, IMG_FILTER_CONTRAST, 255);
imagefilter($im, IMG_FILTER_NEGATE);
imagefilter($im, IMG_FILTER_COLORIZE, 252, 137, 36);


imagejpeg($im);
?>

要使其接近,但我仍然缺少将所有白色阴影变为黑色阴影的功能. http://korlon.com/youknowbetter/filter.php

To get it close but I am still missing the ability to turn all the white shades to black shades. http://korlon.com/youknowbetter/filter.php

我已尝试按照此问题的指示将白色换成黑色: 可以使用GD库在PHP?

I have tried swapping out white for black as instructed in this question here: Can I swap colors in image using GD library in PHP?

但是,这似乎不起作用.它实际上并不交换颜色.那是因为我使用的是jpg而不是gif吗?调色板需要做些什么吗?

However that doesn't seem to work. It doesn't actually swap out the colors. Is that because I am using a jpg and not a gif? Is there something I need to do with the color palette?

谢谢,任何帮助将不胜感激!

Thanks, any help would be greatly appreciated!

STOOB

推荐答案

使用蓝色(#0276DB)而不是橙色,然后反转图像(使用IMAGE_FILTER_NEGATE)以获得橙色和黑色.

use Blue (#0276DB) instead of orange, and then inverse the image (using IMAGE_FILTER_NEGATE) to get orange and black.

因此,您的代码将是:

<?php
header('Content-type: image/jpeg');
$im = imagecreatefromjpeg('test.jpg');



imagefilter($im, IMG_FILTER_GRAYSCALE);
imagefilter($im, IMG_FILTER_CONTRAST, 255);
imagefilter($im, IMG_FILTER_NEGATE);
imagefilter($im, IMG_FILTER_COLORIZE, 2, 118, 219);
imagefilter($im, IMG_FILTER_NEGATE);

imagejpeg($im);
?>

这篇关于使用PHP GD图像库上色和交换颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆