Jump to content

[SOLVED] wrap image text GDLIB


willpower

Recommended Posts

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

 

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;
}
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.