Anyone wanting to create a reflecion of an image. Simple process that copies, line by line, from the bottom of the image, a given number of pixels. Each line gets gradually more transparent. Outputs PNG to screen.
This is pretty hot-coded - all four input variables (input image, reflection height, starting transparency, gap between image and reflection) are set manually here.
<?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);
?>