php 图片透明,PHP怎么把一张图片透明化
PHP怎么把一張圖片透明化?
具體問題:
把一張圖片(根據指定的RGB顏色范圍)透明化。但是實際處理當中,下面的代碼值移除了白色,請教是怎么回事?$o_pic = '1.jpg';
//要處理的色階起始值
$begin_r = 215;
$begin_g = 215;
$begin_b = 215;
list($src_w,$src_h,$src_type) = getimagesize($o_pic);// 獲取原圖像信息
$file_ext = get_ext($o_pic);//獲取擴展名
$target_im = imagecreatetruecolor($src_w,$src_h);//新圖
if($file_ext == 'jpg') //轉換JPG 開始
{
$src_im = ImageCreateFromJPEG($o_pic);
imagecopymerge($target_im,$src_im,0,0,0,0,$src_w,$src_h,100);
for($x = 0; $x < $src_w; $x++)
{
for($y = 0; $y < $src_h; $y++)
{
$rgb = imagecolorat($src_im, $x, $y);
$r = ($rgb >> 16) & 0xFF;
$g = ($rgb >> 8) & 0xFF;
$b = $rgb & 0xFF;
if($r > $begin_r && $g > $begin_g && $b > $begin_b ){
imagecolortransparent($target_im, imagecolorallocate($target_im,$r, $g, $b));
}
}
}
}
方法:/**
* Created by PhpStorm.
* User: shellus
* Date: 2016-12-01
* Time: 23:12
*/
require 'vendor/autoload.php';
// import the Intervention Image Manager Class
use Intervention\Image\ImageManager;
// create an image manager instance with favored driver
$manager = new ImageManager(array('driver' => 'gd'));
$img = $manager->make('1.jpg');
for ($y = 0; $y < $img->height(); $y++)
{
for ($x = 0; $x < $img->width(); $x++)
{
$c = $img -> pickColor($x, $y, 'array');
if(abs($c[0] - 205) < 50 && abs($c[1] - 223) < 50 && abs($c[2] - 211) < 50 ){
$c[0] = $c[1] = $c[2] = 255;
$img -> pixel($c, $x, $y);
更多相關技術文章,請訪問PHP中文網!
本文原創發布php中文網,轉載請注明出處,感謝您的尊重!
總結
以上是生活随笔為你收集整理的php 图片透明,PHP怎么把一张图片透明化的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: php需要什么技能,成为一个好的PHP工
- 下一篇: pdf 中的java运行,java -