任何想要创建图像镜像的人。一个简单的过程,从图像底部逐行复制给定数量的像素。每行逐渐变得更加透明。输出 PNG 到屏幕。
这段代码相当硬编码 - 所有四个输入变量(输入图像、镜像高度、起始透明度、图像和镜像之间的间隙)都在这里手动设置。
<?php
$in = imagecreatefromjpeg('C:\test.jpg');
$reflection_strength = 120; $reflection_height = 40; $gap = 10; $orig_height = imagesy($in); $orig_width = imagesx($in); $output_height = $orig_height + $reflection_height + $gap; $out = imagecreatetruecolor($orig_width, $output_height);
imagealphablending($out, false);
$bg = imagecolortransparent($out, imagecolorallocatealpha($out, 255, 255, 255, 127));
imagefill($out, 0, 0, $bg);
imagefilledrectangle($out, 0, 0, imagesx($in), imagesy($in), $bg1);
imagecopyresampled ( $out , $in , 0, 0, 0, 0, imagesx($in), imagesy($in), imagesx($in), imagesy($in));
$reflection_section = imagecreatetruecolor(imagesx($in), 1);
imagealphablending($reflection_section, false);
$bg1 = imagecolortransparent($reflection_section, imagecolorallocatealpha($reflection_section, 255, 255, 255, 127));
imagefill($reflection_section, 0, 0, $bg1);
for ($y = 0; $y<$reflection_height;$y++)
{
$t = ((127-$reflection_strength) + ($reflection_strength*($y/$reflection_height)));
imagecopy($reflection_section, $out, 0, 0, 0, imagesy($in) - $y, imagesx($in), 1);
imagefilter($reflection_section, IMG_FILTER_COLORIZE, 0, 0, 0, $t);
imagecopyresized($out, $reflection_section, $a, imagesy($in) + $y + $gap, 0, 0, imagesx($in) - (2*$a), 1, imagesx($in), 1);
}
header('Content-type: image/png');
imagesavealpha($out,true);
imagepng($out);
?>