note 60412 added to ref.image

From: Date: Fri, 06 Jan 2006 01:35:27 +0000
Subject: note 60412 added to ref.image
Groups: php.notes 
Request: Send a blank email to php-notes+get-101285@lists.php.net to get a copy of this message
I wanted to create a cool dynamic image, to show how long until my wedding. This may n ot be the best way to do it, but it works nicely. (perhaps someone can suggest some better php functions (imagefttext) may be outdated? Anyhow, I created 6 background images (I made some pixel people with a speech bubble). Make them look different, name them banner.png, banner1.png etc. however many you have, don't forget to match the number in the "random" count. I also added some dorky remarks for "string1" Hope someone enjoys this. get creative, you can also make the font random, as well as the color. <?php header("Content-type: image/png"); $number1 = rand(1,8); if($number1==1)$string1 = "Sweet, "; if($number1==2)$string1 = "WOW!, "; if($number1==3)$string1 = "OMG!, "; if($number1==4)$string1 = "YAY!, "; if($number1==5)$string1 = "Cool!, "; if($number1==6)$string1 = "Hey!, "; if($number1==7)$string1 = "Super!, "; if($number1==8)$string1 = "Zoinks!, "; $number2 = rand(1,6); if($number2==1)$string2 = "banner.png"; if($number2==2)$string2 = "banner1.png"; if($number2==3)$string2 = "banner2.png"; if($number2==4)$string2 = "banner3.png"; if($number2==5)$string2 = "banner4.png"; if($number2==6)$string2 = "banner5.png"; // we choose the date for our occasion $day = 12; // Day of the countdown $month = 12; // Month of the countdown $year = 2006; // Year of the countdown $hour = 15; // Hour of the day (east coast time) $event = " our Wedding"; //event $calculation = ((mktime ($hour,0,0,$month,$day,$year) - time(void))/3600); $hours = (int)$calculation; $days = (int)($hours/24); if ($days > 0 ) $valuate = "until" ; else { $valuate = "since" ;} $string3 = $string1 . $days." days ". $valuate . $event ; // set the path to your background images $im = imagecreatefrompng("http://www.your.com/".$string2); $text = imagecolorallocate($im, 0, 0, 0); //Text Color RGB Values // upload a ttf font, i chose hooge, as a lovely pixel font imagefttext ($im, 6, 0, 20, 18, $text, "hooge_055.ttf", $string3 , array()); //Write the foreground Text // 8=Font Size 0=Angle 1=Dist from left 10=Dist from top imagepng($im); //Draws the image imagedestroy($im); //Finish the image. ?> ---- Manual Page -- http://www.php.net/manual/en/ref.image.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+60412 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+60412&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+60412&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+60412&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+60412&report=yes&reason=useless Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+60412&report=yes&reason=non-english Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+60412&report=yes&reason=already+in+docs Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+60412&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+60412&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#101285) next »