Jragon Posted December 13, 2010 Share Posted December 13, 2010 Hey, I would like to be able to show more than one image that is made by php on the fly. The two codes i want to join: hitcounter <?php /** * @author Jragon * @copyright 2010 */ getHits(); function getHits() { $file = "hits.txt"; $fh = fopen($file, "r"); $hits = @fread($fh, filesize("$file")); fclose($fh); if ($hits <= 0){ $hits =1; } else { ++$hits; } $fh = fopen($file, "w+"); fwrite($fh, "$hits"); fclose($fh); getImage("$hits"); } function getImage($string) { //Make $string to to a string $string = "$string"; //Define fontsize $font = 5; //use imagefontwidth to find out the widht of each charicter, //then times it by how many charicters theere are, //and add some padding. $width = imagefontwidth($font) * strlen($string) + 10; //height of a charicter, and add some padding. $height = imagefontheight($font) + 10; //random color thingy. $r = rand(25, 250); $g = rand(25, 250); $b = rand(25, 250); //create a blank image using the dimsions set above. $image = imagecreate($width, $height); //set the background color $background_color = imagecolorallocate($image, 0, 0, 0); //set the text color using the random integers made above. $text_color = imagecolorallocate($image, $r, $g, $b); //Put the text into the image. imagestring($image, $font, 6, 6, $string, $text_color); //Change the type of webpage so you see the image header("Content-type: image/png"); //put everything together and make the image imagepng($image); //free up some space on the temp drive imagedestroy($image); } ?> and my random quote thingy: <?php /** * @author Jragon * @copyright 2010 */ $textfile = "quotes.txt"; $quotes = array(); if(file_exists($textfile)){ $quotes = explode("\n",file_get_contents($textfile)); srand ((float) microtime() * 10000000); $string = $quotes[array_rand($quotes)]; text_to_image($string, 800); } else { $string = "Sig file non-existant..."; } function text_to_image($text, $image_width) { $r = rand(25, 250); $g = rand(25, 250); $b = rand(25, 250); $font = 5; $line_height = 15; $padding = 5; $text = wordwrap($text, ($image_width/10)); $lines = explode("\n", $text); $image = imagecreate($image_width,((count($lines) * $line_height)) + ($padding * 2)); $background = imagecolorallocate($image, 0, 0, 0); $colour = imagecolorallocate($image, $r, $g, $b); imagefill($image, 0, 0, $background); $i = $padding; foreach($lines as $line){ imagestring($image, $font, $padding, $i, trim($line), $colour); $i += $line_height; } header("Content-type: image/jpeg"); imagejpeg($image); imagedestroy($image); exit; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/221544-how-can-i-desply-more-than-one-image/ Share on other sites More sharing options...
AbraCadaver Posted December 13, 2010 Share Posted December 13, 2010 In another page: <img src="hitcounter.php" alt=""> <img src="randomquote.php" alt=""> Quote Link to comment https://forums.phpfreaks.com/topic/221544-how-can-i-desply-more-than-one-image/#findComment-1146811 Share on other sites More sharing options...
Jragon Posted December 13, 2010 Author Share Posted December 13, 2010 I have reached the max ammount of images on my forum siggy, and i want it to be one php file but two images. Quote Link to comment https://forums.phpfreaks.com/topic/221544-how-can-i-desply-more-than-one-image/#findComment-1146828 Share on other sites More sharing options...
AbraCadaver Posted December 13, 2010 Share Posted December 13, 2010 I rarely use the image functions but it looks like you are familiar with them. Each of your functions needs to return the image instead of displaying it. Then use the imagecreate...() and imagecopy() functions to build one from the two. Quote Link to comment https://forums.phpfreaks.com/topic/221544-how-can-i-desply-more-than-one-image/#findComment-1146831 Share on other sites More sharing options...
Jragon Posted December 13, 2010 Author Share Posted December 13, 2010 But that would just save it would'nt it? and i need it to desply the image when you do the Quote Link to comment https://forums.phpfreaks.com/topic/221544-how-can-i-desply-more-than-one-image/#findComment-1146833 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.