Jump to content

GD images! <- ha, that looks wrong. Imagecreate, imagecreatetruecolor problem


Alex-Grim

Recommended Posts

Hey guys, i've got a question about the imagecreate function. It seems that if i use this in a function, that i cannot directly output the image to the browser, as i get the following error:

The image “http://alexgrim.test/includes/classes/tmp.php” cannot be displayed, because it contains errors.

 

So far, this wasn't an issue, because i'm writing them to disk when uploaded. But now, the problem is that i'm generating random number images to verify that you are human. Well, i can't output the dynamically created image to the browser if i use it in a class method, yet, if i include it directly into the page it's being used from, it's just fine?

 

Here is my code, but keep in mind that i have also tried using output buffering to see if that matters, but it made no difference. This is the page that calls the class method:

<?php
include_once("Image.php");

$i   = new Image(null);

$rslt=$i->RandomImg('667');
?>

And here's the method:

	function RandomImg($str){
	header ("Content-type: image/jpg");
	$im = @imagecreatetruecolor(120, 60);
	$text_color = imagecolorallocate($im, 233, 14, 91);
	imagestring($im, 1, 5, 5, $str, $text_color);
	imagejpeg($im);
	imagedestroy($im);
}

I have tried directly copying the code from php.net for this, and, as i have already said, it didn't work unless i run it on the page i'm using it on, directly. I can't call it as a method.

 

Thanx

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.