Skip to content

Instantly share code, notes, and snippets.

@andrienko
Last active August 29, 2015 14:13
Show Gist options
  • Save andrienko/4503d50e1f3ceb34c166 to your computer and use it in GitHub Desktop.
Save andrienko/4503d50e1f3ceb34c166 to your computer and use it in GitHub Desktop.
<?php
// Loading plish from hard drive and getting plish dimentions
$plish = imagecreatefrompng('plish.png');
list($x,$y) = array(imagesx($plish),imagesy($plish));
// --- Creating black image with dots
// Creating new image (black by default) with dimentions of a plish
$dots = imagecreatetruecolor($x,$y);
$white = imagecolorallocate($dots,255,255,255);
// Placing dots over black image
foreach(range(1,100) as $num)
imagefilledellipse($dots, rand(0,$x-1), rand(0,$y-1), 5, 5, $white);
// Blurring black image (5 times).
// At this point we have black background with white blurry dots
foreach(range(1,5) as $i)
imagefilter($dots,IMG_FILTER_GAUSSIAN_BLUR);
// Copying white from dots image back onto plish
for($xi = 0;$xi<$x;$xi++){
for($yi=0;$yi<$y;$yi++) {
$alpha = (1 - ((imagecolorat($dots,$xi,$yi) & 0xFF)) / 255) * 127;
if($alpha>0) {
$pixel_color = imagecolorallocatealpha($plish, 255, 255, 255, $alpha);
imagesetpixel($plish, $xi, $yi, $pixel_color);
}
}
}
header ('Content-Type: image/png');
imagepng($plish,null);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment