$imgsrc = imagecreatefromstring(file_get_contents('image.jpg')); $imgsrcw = imagesx($imgsrc); $imgsrch = imagesy($imgsrc); $width = 1920; $x1 = 0; $x2 = $imgsrcw - $x1 - 20; $y1 = 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), $y2, ($i+$x1+1), $y1, $alpha); // 修改这里,让渐变从上往下 } header('content-type: image/jpeg'); imagejpeg($imgsrc,'09.jpg'); imagedestroy($imgsrc);

PHP 图片渐变效果:从下往上实现

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

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