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

yipeiwu_com5年前PHP代码库

复制代码 代码如下:

<?php
////$strimgsrc = file_get_contents("/zb_users/upload/202003/e4lf1fxwbqa.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);
?>

相关文章

php装饰者模式简单应用案例分析

本文实例讲述了php装饰者模式简单应用。分享给大家供大家参考,具体如下: 装饰模式指的是在不必改变原类文件和使用继承的情况下,动态地扩展一个对象的功能。它是通过创建一个包装对象,也就是装...

DISCUZ 论坛管理员密码忘记的解决方法

DISCUZ论坛管理员密码忘记了怎么办? 今天,一个朋友在QQ上问我,“如果DISCUZ论坛管理员密码忘记了 从MYSQL 哪里找啊?”, 他用的是HostMonster的虚拟主机。 y...

PHP设计模式 注册表模式(多个类的注册)

以前我也写过一个注册表类,不过那一个不能进行多个类的注册,下面用数组对类进行了存储。 复制代码 代码如下: <?php //基础类 class webSite {//一个非常简单的...

redis+php实现微博(二)发布与关注功能详解

本文实例讲述了redis+php实现微博发布与关注功能。分享给大家供大家参考,具体如下: 数据结构: set post:postid:3:time timestamp set post...

PHP动态生成指定大小随机图片的方法

本文实例讲述了PHP动态生成指定大小随机图片的方法。分享给大家供大家参考,具体如下: <?php $image_width = 100; $image_height =...