📜 ⬆️ ⬇️

Beware of slippery! We play with the image in PCP. The effect of wet floor.

How to realize the effect of wet floor?

And everything is very simple!

You just need to go under the “cut” and see ... =)
')
Task: to realize the effect of wet floor

Solution: PHP + GD
And everything is simple ... =)

Code without explanation ...
I think who needs it, and they will understand.

function reflection(&$img,$perc=50,$maxAlpha=127)
{
$src_height = imagesy($img);
$src_width = imagesx($img);
$dest_height = $src_height + ($src_height / (100/$perc));
$dest_width = $src_width;

$reflected = imagecreatetruecolor($dest_width, $dest_height);
imagealphablending($reflected, false);
imagesavealpha($reflected, true);

imagecopy($reflected, $this->img, 0, 0, 0, 0, $src_width, $src_height);
$reflection_height = $src_height / 2;
for($y=$src_height;$y<$dest_height;$y++)
{
$alpha = (($y-$src_height)/($dest_height-$src_height))*$maxAlpha;
for($x=0;$x<$src_width;$x++)
{
$rgba = imagecolorat($img, $x, $src_height - ($y-$src_height+1));
$rgba = imagecolorsforindex($img, $rgba);
$rgba = imagecolorallocatealpha($reflected, $rgba['red'], $rgba['green'], $rgba['blue'], $alpha);
imagesetpixel($reflected, $x, $y, $rgba);
}
}
$img = $reflected;
}


UPD At the request of workers
Example:
image

The test and code with highlighting can be found in my blog .

Source: https://habr.com/ru/post/41231/


All Articles