PHP Random Heart Image Generator Draw Hearts
Posted by hawk under Dirty ScriptsLet Me Hear Your Thoughts >>
Happy Valentines Day!
I have a special valentines day random heart generator. This script below will create 100 hearts in random shapes and sizes as a png. Just hit refresh to try it out.
It draws hearts the simple way, two circles and a triangle. As with most scripts the width, height size ect are all pretty easily editable. Enjoy.
PHP Heart Generator that Draws Hearts using GD.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | <?php $imwidth = 500; $imheight = 150; $im = imagecreate($imwidth,$imheight); $background_color = imagecolorallocate($im,255,255,255); $hearts = 100; function drawheart($im){ global $imwidth,$imheight; $leftx = rand(0,$imwidth); $lefty = rand(0,$imheight); $circle_diameter = rand(3,$imwidth/12); $rightx = $leftx + $circle_diameter * .9; $righty = $lefty; $circle_radius = $circle_diameter/2; $points = array($leftx-$circle_radius,$lefty,$leftx+$circle_radius,$lefty+$circle_diameter+5,$rightx+$circle_radius,$righty,$leftx-$circle_radius,$lefty); $color = imagecolorallocate($im,255,0,0); imagefilledellipse($im,$leftx,$lefty,$circle_diameter,$circle_diameter,$color); imagefilledellipse($im,$rightx,$righty,$circle_diameter,$circle_diameter,$color); imagefilledpolygon($im,$points,4,$color); return $im; } ; for($i=0;$i<$hearts;$i++){ $im = drawheart($im); } header('Content-type:image/png'); imagepng($im); imagedestroy($im); ?> |
Have a happy fun filled valentines day and enjoy your loved ones.











