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

PHP
php教程:mysql数据库操作的DB类
PHP教程:cookie和数组的结合实现购物车
php教程:mysql的常用语句
php教程:经典PHP代码
php编程中遇到的cookie的问题
php入门交流:鼓励学习PHP的新手
细数PHP程序的一些缺陷
说明PHP开发网站程序的优点
PHP+MYSQL网站开发中遇到的问题汇总
php教程:php设计模式介绍之工厂模式
ubuntu下apache2不能解释php程序故障
WIN2003+IIS6+PHP5根目录无法运行PHP程序
PHP+MYSQL网站开发中关于时间的问题
PHP正则表达式提取超链接及其标题
PHP中的Date()函数详细讲解
初学:apache与php基本配置
PHP串行化与JSON
php教程:php设计模式介绍之单条模式
PHP中不能使用exec(),system(),shell_system()等函数
PHP正则表达式从url中取得域名

PHP 中的 php 图片上添加透明度渐变的效果


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

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

复制代码 代码如下:

<?php
////$strimgsrc = file_get_contents("http://127.0.0.1//upload/tech/20091012/20091012021527_46922a0880a8f11f8f69cbb52b1396be.jpg");
////$imgsrc = imagecreatefromstring($strimgsrc);
$imgsrc = imagecreatefromjpeg("/upload/tech/20091012/20091012021527_46922a0880a8f11f8f69cbb52b1396be.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);
?>