以下代码将创建图像的反射,但仅反射。 我希望它在原始图像下添加这个反射。
这是我的代码:
<?php
$im = 'path/to/image.jpg'; // The input image
$size = getimagesize($im);
$rH = 50; // Reflection height
$tr = 30; // Starting transparency
$div = 1; // Size of the divider line
$w = $size[0];
$h = $size[1];
$im = imagecreatefromjpeg($im);
$li = imagecreatetruecolor($w, 1);
$bgc = imagecolorallocate($li, 255, 255, 255); // Background color
imagefilledrectangle($li, 0, 0, $w, 1, $bgc);
$bg = imagecreatetruecolor($w, $rH);
$wh = imagecolorallocate($im,255,255,255);
$im = imagerotate($im, -180, $wh);
imagecopyresampled($bg, $im, 0, 0, 0, 0, $w, $h, $w, $h);
$im = $bg;
$bg = imagecreatetruecolor($w, $rH);
for ($x = 0; $x < $w; $x++) {
imagecopy($bg, $im, $x, 0, $w-$x, 0, 1, $rH);
}
$im = $bg;
$in = 100/$rH;
for($i=0; $i<=$rH; $i++){
if($tr>100) $tr = 100;
imagecopymerge($im, $li, 0, $i, 0, 0, $w, 1, $tr);
$tr+=$in;
}
imagecopymerge($im, $li, 0, 0, 0, 0, $w, $div, 100); // Divider
header('content-type: image/jpeg');
imagejpeg($im, '', 100);
imagedestroy($im);
imagedestroy($li);
?>