willpower Posted September 9, 2007 Share Posted September 9, 2007 Hi has anyone successfully wrapped text in a image generated on the fly? If so can you let me know how. Thanks Will Link to comment https://forums.phpfreaks.com/topic/68637-solved-wrap-image-text-gdlib/ Share on other sites More sharing options...
tippy_102 Posted September 9, 2007 Share Posted September 9, 2007 Have you read the User Comments posted at the bottom of the php.net imagestring page? There are a number of examples for wrapping text. http://ca.php.net/imagestring Link to comment https://forums.phpfreaks.com/topic/68637-solved-wrap-image-text-gdlib/#findComment-345008 Share on other sites More sharing options...
willpower Posted September 10, 2007 Author Share Posted September 10, 2007 Ok so now i have this <? $title="this is my wrapped text, yes my wrapped text and i really neeeeeeeeeeeeeed to wrap the text text text"; $imgfile= 'blank.png'; $outfile=@ImageCreateFromPNG($imgfile); $red=imagecolorallocate($outfile,255,0,0); $grey=imagecolorallocate($outfile,128,128,128); $font1='arial.ttf'; $maxwidth=363; function ImageStringWrap($imgfile, $font1, $x, $y, $title, $red, $maxwidth) { $fontwidth = ImageFontWidth($font1); $fontheight = ImageFontHeight($font1); if ($maxwidth != NULL) { $maxcharsperline = floor($maxwidth / $fontwidth); $text = wordwrap($text, $maxcharsperline, "\n", 1); } $lines = explode("\n", $title); while (list($numl, $line) = each($lines)) { ImageString($imgfile, $font1, $x, $y, $line, $red); $y += $fontheight; } } ImageStringWrap($imgfile, $font1, 0, $y, $title, $red, ImageSX($imgfile) ); imagepng ($outfile); imagedestroy($outfile); ?> But I get these error messages...any ideas? Warning: imagesx(): supplied argument is not a valid Image resource in /home/amydomain/public_html/quoteimage.php on line 28 Warning: imagestring(): supplied argument is not a valid Image resource in /home/mydomain/public_html/quoteimage.php on line 23 Link to comment https://forums.phpfreaks.com/topic/68637-solved-wrap-image-text-gdlib/#findComment-345036 Share on other sites More sharing options...
tippy_102 Posted September 10, 2007 Share Posted September 10, 2007 imagesx will only work with one of the GD image creation functions. Here - try this....you'll have to work with it to make it pretty. <?php header ("Content-type: image/png"); $string = "this is my wrapped text, yes my wrapped text and i really neeeeeeeeeeeeeed to wrap the text text text" ; $font = "Arial.ttf"; $width = 300; $height = 100; $image = imagecreate ($width, $height); $back = ImageColorAllocate($image, 255, 255, 255); $border = ImageColorAllocate($image, 0, 0, 0); ImageFilledRectangle($image, 0, 0, $width, $height, $border); ImageFilledRectangle($image, 1, 1, $width-2, $height-2, $back); $text_color = imagecolorallocate ($image, 255, 0, 0); ImageStringWrap($image, $font, 3, 2, $string, $text_color, $width-2 ); imagepng ($image); function ImageStringWrap($image, $font, $x, $y, $text, $color, $maxwidth) { $fontwidth = ImageFontWidth($font); $fontheight = ImageFontHeight($font); if ($maxwidth != NULL) { $maxcharsperline = floor($maxwidth / $fontwidth); $text = wordwrap($text, $maxcharsperline, "\n", 1); } $lines = explode("\n", $text); while (list($numl, $line) = each($lines)) { ImageString($image, $font, $x, $y, $line, $color); $y += $fontheight; } } Link to comment https://forums.phpfreaks.com/topic/68637-solved-wrap-image-text-gdlib/#findComment-345137 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.