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
https://forums.phpfreaks.com/topic/84564-gd-images/
Share on other sites

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.