radioactive Posted May 15, 2012 Share Posted May 15, 2012 I want to implement the code within other PHP, and HTML divs. I set the content type to image/png, which is currently the cause of my problem. The image will not display because the whole file is running off a certain content type. No other content will display either. Also, is it possible to set the font as well as the size? <?php header("Content-type: image/png"); $size = 10; $width = 700; $height = 200; $string = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed ut magna a odio auctor vulputate. Sed condimentum condimentum lorem, sit amet suscipit leo porta in. Integer justo risus, tincidunt sed blandit a, mollis eu enim. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Aliquam dictum, lorem euismod vulputate mattis, purus ligula tristique libero, id vulputate lorem est eget neque. Nulla turpis enim, lobortis eget suscipit ac, vestibulum et augue. Sed id magna quam. Curabitur interdum, tortor luctus egestas rhoncus, ipsum lectus rutrum metus, ut venenatis lorem enim et risus."; $image = imagecreate($width, $height); $background = ImageColorAllocate($image, 255, 255, 255); $color = imagecolorallocate ($image, 0, 0, 0); image_create($image, $size, 3, 2, $string, $color, $width); imagepng($image); function image_create($image, $size, $x, $y, $text, $color, $maxwidth) { $fontwidth = ImageFontWidth($size); $fontheight = ImageFontHeight($size); if ($maxwidth != NULL) { $maxchar = floor($maxwidth / $fontwidth); $text = wordwrap($text, $maxchar, "\n", 1); } $lines = explode("\n", $text); while (list($numl, $line) = each($lines)) { ImageString($image, $size, $x, $y, $line, $color); $y += $fontheight; } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/262548-imagestring/ Share on other sites More sharing options...
Barand Posted May 15, 2012 Share Posted May 15, 2012 Keep the image code in its own file say, string.php. Display in other pages as you would any other image ie with img tag <img src="string.php?text=lorem ipsum" /> BTW you need imageDestroy($image) after the imagePng($image) Quote Link to comment https://forums.phpfreaks.com/topic/262548-imagestring/#findComment-1345547 Share on other sites More sharing options...
radioactive Posted May 15, 2012 Author Share Posted May 15, 2012 It's working now, thanks. Is it also possible to change the font? Quote Link to comment https://forums.phpfreaks.com/topic/262548-imagestring/#findComment-1345593 Share on other sites More sharing options...
Barand Posted May 15, 2012 Share Posted May 15, 2012 imagestring is limited to its built-in fonts (1-5); Look at imagettftext() Quote Link to comment https://forums.phpfreaks.com/topic/262548-imagestring/#findComment-1345674 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.