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

PHP
PHP删除MYSQL数据库中所有表的代码
php教程:php设计模式介绍之注册模式
php教程:php设计模式介绍之伪对象模式
PHPnow轻松打造专业PHP服务器环境
php教程:php设计模式介绍之策略模式
php教程:php设计模式介绍之迭代器模式
Windows环境下Apache与Tomcat共存
简单学习php遇到的主要问题
php教程:php设计模式介绍之观测模式
php教程:php设计模式介绍之规范模式
php教程:php设计模式介绍之代理模式
php教程:php设计模式介绍之装饰器模式
Perl操作mysql数据库的方法
php教程:php设计模式介绍之适配器模式
PHP单件模式和命令链模式的基础知识
PHP大师指点:优秀的PHP代码怎么来?
PHP开发的Myers 订单跟踪系统 (MOTS)
PHP控制网页过期时间的程序
Cannot modify header information出错的原因
PHP 5.3的date_create_from_format()函数

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


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-10-12   浏览: 120 ::
收藏到网摘: 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);
?>