Luigi987 Posted July 23, 2010 Share Posted July 23, 2010 Hello, I have this PHP script I made that is basically a php dynamic PNG image and I want to be able to use http://example.com/image.php?red to show it with a red background and so on. Here's my code: <?php // are we POSTing data? if($_POST["name"] && $_POST["line"]) { updateTags(' <' . substr(stripcslashes($_POST["name"]), 0, 14) . '> ' . substr(stripcslashes($_POST["line"]), 0, 60)); } else { // if not, let's display the tagboard thigny displayImage(); } function updateTags($newline) { //the data $data = "$newline"; //open the file and choose the mode $fh = fopen("archive.txt", "a"); fwrite($fh, $data."\n"); //close the file fclose($fh); $file = file('./messages.txt'); // Okay, what this does is: // 1. Copy lines 0-400 to positions 1-18. for($i = 1; $i < 29; $i++) { $file[$i] = $file[$i+1]; } // 2. Replace line 19 with the new line. $file[29] = "\n" . $newline; // 3. Write file_put_contents('./messages.txt',$file); // 4. Redirect the user to the last page they were on ?><head><META http-equiv="refresh" content="1;URL=<? echo $_SERVER['HTTP_REFERER']; ?>#tagboard"></head><?php } function displayImage() { $font = "./start.ttf"; // This stuff was for testing purposes. //$line = "<12345678901234> 618203089397031759542093136045940823181599051328925062729983961751505864647211170984368632377438"; //$bbox = imagettfbbox(6, 0, $font, $line); //echo $bbox[0] . ', ' . $bbox[1] . "<br>"; //echo $bbox[2] . ', ' . $bbox[3] . "<br>"; //echo $bbox[4] . ', ' . $bbox[5] . "<br>"; //echo $bbox[6] . ', ' . $bbox[7] . "<br>"; $image = ImageCreateFromPNG("base.png"); $black = imagecolorallocate($image, 0, 0, 0); imagefill($image, 0, 0, $black); $white = imagecolorallocate($image, 255, 255, 255); $shadow = imagecolorallocate($image, 0x66, 0x66, 0x66); $file = file('./messages.txt'); imagettftext($image, 6, 0, 0, 8, $white, $font, $file[0]); for($i = 2; $i <= 30; $i++) { // I forget exactly what possessed me to write this line this way. imagettftext($image, 6, 0, 0, (8 * $i) + ($i-1), $white, $font, $file[$i-1]); } // let's be neat - add the proper header and free allocated memory header('Content-type: image/png'); header("Expires: Mon, 20 Dec 1998 01:00:00 GMT"); header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); // cover multiple bases to BLOCK caching so I can just tell it to reload the page header("Cache-Control: no-cache, must-revalidate"); header("Pragma: no-cache"); imagepng($image); imagedestroy($image); } ?> The place of the thing I wanna change is the: $image = ImageCreateFromPNG("base.png"); Part to use another image rather than base.png and use red.png in this example. Help greatly appreciated. ~Luigi987 Link to comment https://forums.phpfreaks.com/topic/208629-using-_get-to-change-which-image-to-use/ Share on other sites More sharing options...
Luigi987 Posted July 23, 2010 Author Share Posted July 23, 2010 Never mind, I figured it out. Link to comment https://forums.phpfreaks.com/topic/208629-using-_get-to-change-which-image-to-use/#findComment-1089980 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.