note 81828 deleted from ref.image by tularis

From: Date: Sun, 29 Jun 2008 20:59:24 +0000
Subject: note 81828 deleted from ref.image by tularis
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-140909@lists.php.net to get a copy of this message
Note Submitter: troy --at-- goemr.com ---- Here is a fun example Easter Egg drawing that uses a bunch of image functions. Just in time for Easter 2008. Enjoy. <?php $image = imagecreatetruecolor(400, 500); $bg = imagecolorallocate($image, 10, 10, 150); imagefill($image, 0, 0, $bg); // allocate some colors $white = imagecolorallocate($image, 255, 255, 255); $grey = imagecolorallocate($image, 128, 128, 128); $black = imagecolorallocate($image, 0, 0, 0); // choose a color for the elipse $col_ellipse = imagecolorallocate($image, 255, 200, 255); // draw ellipse shadow imagefilledellipse($image, 215, 265, 320, 400, $black); // draw the ellipse imagefilledellipse($image, 200, 250, 320, 400, $col_ellipse); //draw arc where plastic egg opens imagearc($image, 198, 235, 326, 100, 0, 180, $bg); $colour = imagecolorallocate($image, 100, 0, 200); $ca = rand(2,5); $cb = rand(2,5); $cc = rand(2,5); $cd = rand(2,5); ${"colour".$ca} = imagecolorallocate($image, 153, 204, 255); ${"colour".$cb} = imagecolorallocate($image, 102, 0, 153); ${"colour".$cc} = imagecolorallocate($image, 204, 153, 204); ${"colour".$cd} = imagecolorallocate($image, 153, 0, 255); //positions of stars relative to original position $shift['x'][]=0; //star 1 $shift['y'][]=0; $star['color'][] = $colour; $shift['x'][]=-80; //star 2 $shift['y'][]=-120; $star['color'][] = $colour2; $shift['x'][]=-130; //star 3 $shift['y'][]=10; $star['color'][] = $colour3; $shift['x'][]=-10; //star 4 $shift['y'][]=-250; $star['color'][] = $colour4; $shift['x'][]=-160; //star 5 $shift['y'][]=-200; $star['color'][] = $colour5; for($ii=0; $ii < count($shift['x']); $ii++) { // set up array of points for polygon $values = array( 230, 330, 290, 390, 280, 340, 240, 380, 310, 370, 230, 330 ); $shiftX = $shift['x'][$ii]; $shiftY = $shift['y'][$ii]; foreach ($values as &$val) { if($i == 1){ $val = $val+$shiftY; $i++; } else { $val = $val+$shiftX; $i = 1; } } // draw a star filled in with a circle imagefilledpolygon($image, $values, 6, $star['color'][$ii]); imagefilledellipse($image, 273+$shiftX, 364+$shiftY, 35, 24, $star['color'][$ii]); }//end for // Rotate $degrees = rand(0,360); $image= imagerotate($image, $degrees, 0); imagefilter($image, IMG_FILTER_MEAN_REMOVAL, 0); imagefilter($image, IMG_FILTER_SMOOTH, 0); //add some text $text = 'Easter Egg by Troy Jordan 2008 using only php & gd'; //place font in same path as this script putenv('GDFONTPATH=' . realpath('.')); //change this font to the name of your font $font = 'ACAKZIDE.TTF'; // Add some shadow to the text imagettftext($image, 18, 0, 13, 21, $grey, $font, $text); // Add the text imagettftext($image, 18, 0, 12, 20, $white, $font, $text); //resize the image $width = imagesx($image); $height = imagesy($image); if($height > 0) { $ratio = $width/$height; } $rand = rand(25,75); $perc = $rand/100; $newwidth = $width * $perc; $newheight = $height * $perc; $image2 = imagecreatetruecolor($newwidth, $newheight); imagecopyresampled($image2, $image, 0, 0, 0, 0, $newwidth, $newheight, $width, $height); header("Content-type: image/png"); imagepng($image2); ?>

« previous php.notes (#140909) next »