$imgsrc = imagecreatefromstring(file_get_contents('image.jpg')); $imgsrcw = imagesx($imgsrc); $imgsrch = imagesy($imgsrc); $height = 1080; $x1 = 0; $x2 = $imgsrcw - $x1 - 20; $y1 = $height; // 将起始位置设为底部 $y2 = 0; // 将结束位置设为顶部 $steps = $y2 - $y1; for($i = 0; $i > $steps; $i --) // 将循环条件修改为递减 { $alphay = round(-$i/($steps/127))+60; // 将计算透明度的公式修改为递减 if($alphay >= 128) $alphay = 127; $alpha = imagecolorallocatealpha($imgsrc, 255, 255, 255, $alphay); imagefilledrectangle($imgsrc, $x1, ($i+$y1-1), $x2, ($i+$y1), $alpha); // 将绘制矩形的坐标修改为递减 } header('content-type: image/jpeg'); imagejpeg($imgsrc,'09.jpg'); imagedestroy($imgsrc);

PHP代码实现图片从下到上的渐变效果

原文地址: https://www.cveoy.top/t/topic/kwjQ 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录