当前位置: 首页 > 图文教程 > 网络编程 > PHP > PHP动态的在图片上添加透明度渐变的效果

PHP
用PHP调用Oracle存储过程的方法
FleaPHP的安全设置方法
PHP cron中的批处理
php 301转向实现代码
PHP面向对象分析设计的经验原则
PHP伪造referer实例代码
什么是phpDocumentor
php下防止单引号,双引号在接受页面转义的设置方法
php横向重复区域显示二法
PHP集成FCK的函数代码
php 三维饼图的实现代码
php不用GD库生成当前时间的PNG格式图象的程序
10条PHP编程习惯助你找工作
PHP网站基础优化方法小结
40个迹象表明你还是PHP菜鸟
PHP EOT定界符的使用详解
php数组总结篇(一)
利用PHP制作简单的内容采集器的原理分析
php之对抗Web扫描器的脚本技巧
PHP在字符串中查找指定字符串并删除的代码

PHP动态的在图片上添加透明度渐变的效果


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-09-28   浏览: 122 ::
收藏到网摘: n/a

今天因为临时需要,要动态的在图片上添加透明度渐变的效果,在网上找了半天没有相应功能的算法....
 
 自己写了一个:

以下为引用的内容:

<?php
////$strimgsrc = file_get_contents("http://127.0.0.1/5307754.jpg");
////$imgsrc = imagecreatefromstring($strimgsrc);
$imgsrc = imagecreatefromjpeg("5307754.jpg");
$imgsrcw = imagesx($imgsrc);
$imgsrch = imagesy($imgsrc);

$width = 30;
$x1 = 2;
$x2 = $imgsrcw - $x1 - 20;
$y1 = ($imgsrch - $width) - 2;
$y2 = $y1 + $width;

$steps = $x2 - $x1;
for($i = 0; $i < $steps; $i ++)
{
        $alphax = round($i/($steps/127))+60;
        if($alphax >= 128)
                $alphax = 127;
        $alpha = imagecolorallocatealpha($imgsrc, 255, 255, 255, $alphax);
        imagefilledrectangle($imgsrc, ($i+$x1), $y1, ($i+$x1+1), $y2, $alpha);
}

header('content-type: image/jpeg');

imagejpeg($imgsrc);
imagedestroy($imgsrc);
?>