Jump to content

ImageString


radioactive

Recommended Posts

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.