GD installed?

Status
Not open for further replies.

Kames

New Member
Messages
66
Reaction score
0
Points
0
Hi,

Just a quick question. Do you have GD library installed on your servers? (AdEnhanced)

I ask this because my forum software is telling me you don't and I thought this is strange for a server to be with GD.

In case you want to see for yourself look here, on my registration page.

http://scifiplanet.co.uk/board/member.php?action=register
 

The_Magistrate

New Member
Messages
1,118
Reaction score
0
Points
0
Gd is installed, at least it is on the Paid server.

By the way, your site times out when I try to view it.
 

Kames

New Member
Messages
66
Reaction score
0
Points
0
It not the site its the host :)

GD on free servers?
 

YamiKaitou

Member
Messages
636
Reaction score
0
Points
16
Yes, it is. Your problem isn't with GD, it is the fact that phpinfo() is disabled. Your captcha script is trying to use it, so it is throwing an error causing the image to break
 

Kames

New Member
Messages
66
Reaction score
0
Points
0
Can you enable php_info() then? It's a pretty basic requirement really.
 

Corey

I Break Things
Staff member
Messages
34,551
Reaction score
204
Points
63
We have it disabled because it can be used to get a lot of information about the server which makes it easier for people to abuse the service. It's a lot harder for someone to try functions and figure out where things are located than if we tell them.

I would suggest commenting on the line it is trying to do that in or set it to true even though it returns false.

-Corey
 

Kames

New Member
Messages
66
Reaction score
0
Points
0
Can you not enable php_info() for single accounts?

I'm afraid I cannot edit the code it's a 3rd party script and I have no knowledge of it.

It's ironic really to think about it because the image verification that requires the php_info() is in place to stop automated sign ups and spamming on the site/your server. :|
 

YamiKaitou

Member
Messages
636
Reaction score
0
Points
16
Post the script here, maybe someone can edit it for you and remove the usage of phpinfo(). Also, I have found scripts before that don't need phpinfo(), like the one that I created for my site ;)
 

Brandon

Former Senior Account Rep
Community Support
Messages
19,181
Reaction score
28
Points
48
No script should need phpinfo, there are ways to get the information other than phpinfo(), post it here or give us the link the site that made the script, someone will take a look.
 

Kames

New Member
Messages
66
Reaction score
0
Points
0
Ok, I managed to narrow it down to this bit of code I think.

PHP:
if($mybb->settings['captchaimage'] == "on" && function_exists("imagecreatefrompng"))
	{
		$imagehash = $db->escape_string($mybb->input['imagehash']);
		$imagestring = $db->escape_string($mybb->input['imagestring']);
		$query = $db->simple_select(TABLE_PREFIX."captcha", "*", "imagehash='$imagehash' AND imagestring='$imagestring'");
		$imgcheck = $db->fetch_array($query);
		if(!$imgcheck['dateline'])
		{
			$errors[]  = $lang->error_regimageinvalid;
		}
		$db->delete_query(TABLE_PREFIX."captcha", "imagehash='$imagehash'");
	}

Thanks.
 

Corey

I Break Things
Staff member
Messages
34,551
Reaction score
204
Points
63
Change that to
PHP:
        $imagehash = $db->escape_string($mybb->input['imagehash']);
        $imagestring = $db->escape_string($mybb->input['imagestring']);
        $query = $db->simple_select(TABLE_PREFIX."captcha", "*", "imagehash='$imagehash' AND imagestring='$imagestring'");
        $imgcheck = $db->fetch_array($query);
        if(!$imgcheck['dateline'])
        {
            $errors[]  = $lang->error_regimageinvalid;
        }
        $db->delete_query(TABLE_PREFIX."captcha", "imagehash='$imagehash'");
 

Kames

New Member
Messages
66
Reaction score
0
Points
0
Ok I'll give that a try.

I'm having a problem with FTP at the moment. It keeps timing out...
Edit:
It ok ftp's working now. :)
Edit:
Nope, sorry that didn't work.

See for yourself.
Edit:
Just curious have you also disabled the php mail() function?
Edit:
Nevermind I found that out for myself.
But no image verification still doesn't show.

Here is the image captcha file I found.

PHP:
<?php
/**
 * MyBB 1.2
 * Copyright © 2006 MyBB Group, All Rights Reserved
 *
 * Website: http://www.mybboard.net
 * License: http://www.mybboard.net/eula.html
 *
 * $Id: captcha.php 3063 2007-05-15 23:53:07Z chris $
 */

define("IN_MYBB", 1);

define("NO_ONLINE", 1);
require_once "./global.php";

$img_width = 200;
$img_height = 60;

// The following settings are only used for TTF fonts
$min_size = 20;
$max_size = 32;

$min_angle = -30;
$max_angle = 30;

if($mybb->input['imagehash'] == "test")
{
	$imagestring = "MyBB";
}
elseif($mybb->input['imagehash'])
{
	$query = $db->simple_select(TABLE_PREFIX."captcha", "*", "imagehash='".$db->escape_string(strval($mybb->input['imagehash']))."'", array("limit" => 1));
	$regimage = $db->fetch_array($query);
	$imagestring = $regimage['imagestring'];
}
else
{
	return false;
}
	
$ttf_fonts = array();

// We have support for true-type fonts (FreeType 2)
if(function_exists("imagefttext"))
{
	// Get a list of the files in the 'catpcha_fonts' directory
	$ttfdir  = @opendir(MYBB_ROOT."inc/captcha_fonts");
	if($ttfdir)
	{
		while($file = readdir($ttfdir))
		{
			// If this file is a ttf file, add it to the list
			if(is_file(MYBB_ROOT."inc/captcha_fonts/".$file) && get_extension($file) == "ttf")
			{
				$ttf_fonts[] = MYBB_ROOT."inc/captcha_fonts/".$file;
			}
		}
	}
}

// Have one or more TTF fonts in our array, we can use TTF captha's
if(count($ttf_fonts) > 0)
{
	$use_ttf = 1;
}
else
{
	$use_ttf = 0;
}

// Check for GD >= 2, create base image
if(gd_version() >= 2)
{
	$im = imagecreatetruecolor($img_width, $img_height);
}
else
{
	$im = imagecreate($img_width, $img_height);
}

// No GD support, die.
if(!$im)
{
	die("No GD support.");
}

// Fill the background with white
$bg_color = imagecolorallocate($im, 255, 255, 255);
imagefill($im, 0, 0, $bg_color);

// Draw random circles, squares or lines?
$to_draw = rand(0, 2);
if($to_draw == 1)
{
	draw_circles($im);
}
else if($to_draw == 2)
{
	draw_squares($im);
}
else
{
	draw_lines($im);
}

// Draw dots on the image
draw_dots($im);

// Write the image string to the image
draw_string($im, $imagestring);

// Draw a nice border around the image
$border_color = imagecolorallocate($im, 0, 0, 0);
imagerectangle($im, 0, 0, $img_width-1, $img_height-1, $border_color);

// Output the image
header("Content-type: image/png");
imagepng($im);
imagedestroy($im);
exit;

/**
 * Draws a random number of lines on the image.
 *
 * @param resource The image.
 */
function draw_lines(&$im)
{
	global $img_width, $img_height;

	for($i = 10; $i < $img_width; $i += 10)
	{
		$color = imagecolorallocate($im, rand(150, 255), rand(150, 255), rand(150, 255));
		imageline($im, $i, 0, $i, $img_height, $color);
	}
	for($i = 10; $i < $img_height; $i += 10)
	{
		$color = imagecolorallocate($im, rand(150, 255), rand(150, 255), rand(150, 255));
		imageline($im, 0, $i, $img_width, $i, $color);
	}
}

/**
 * Draws a random number of circles on the image.
 *
 * @param resource The image.
 */
function draw_circles(&$im)
{
	global $img_width, $img_height;
	
	$circles = $img_width*$img_height / 100;
	for($i = 0; $i <= $circles; $i++)
	{
		$color = imagecolorallocate($im, rand(180, 255), rand(180, 255), rand(180, 255));
		$pos_x = rand(1, $img_width);
		$pos_y = rand(1, $img_height);
		$circ_width = ceil(rand(1, $img_width)/2);
		$circ_height = rand(1, $img_height);
		imagearc($im, $pos_x, $pos_y, $circ_width, $circ_height, 0, rand(200, 360), $color);
	}
}

/**
 * Draws a random number of dots on the image.
 *
 * @param resource The image.
 */
function draw_dots(&$im)
{
	global $img_width, $img_height;
	
	$dot_count = $img_width*$img_height/5;
	for($i = 0; $i <= $dot_count; $i++)
	{
		$color = imagecolorallocate($im, rand(200, 255), rand(200, 255), rand(200, 255));
		imagesetpixel($im, rand(0, $img_width), rand(0, $img_height), $color);
	}	
}

/**
 * Draws a random number of squares on the image.
 *
 * @param resource The image.
 */
function draw_squares(&$im)
{
	global $img_width, $img_height;
	
	$square_count = 30;
	for($i = 0; $i <= $square_count; $i++)
	{
		$color = imagecolorallocate($im, rand(150, 255), rand(150, 255), rand(150, 255));
		$pos_x = rand(1, $img_width);
		$pos_y = rand(1, $img_height);
		$sq_width = $sq_height = rand(10, 20);
		$pos_x2 = $pos_x + $sq_height;
		$pos_y2 = $pos_y + $sq_width;
		imagefilledrectangle($im, $pos_x, $pos_y, $pos_x2, $pos_y2, $color); 
	}
}

/**
 * Writes text to the image.
 *
 * @param resource The image.
 * @param string The string to be written
 */
function draw_string(&$im, $string)
{
	global $use_ttf, $min_size, $max_size, $min_angle, $max_angle, $ttf_fonts, $img_height, $img_width;
	
	if(empty($string))
	{
		return false;
	}
	
	$spacing = $img_width / my_strlen($string);
	$string_length = my_strlen($string);
	for($i = 0; $i < $string_length; $i++)
	{
		// Using TTF fonts
		if($use_ttf)
		{
			// Select a random font size
			$font_size = rand($min_size, $max_size);
			
			// Select a random font
			$font = array_rand($ttf_fonts);
			$font = $ttf_fonts[$font];
	
			// Select a random rotation
			$rotation = rand($min_angle, $max_angle);
			
			// Set the colour
			$r = rand(0, 200);
			$g = rand(0, 200);
			$b = rand(0, 200);
			$color = imagecolorallocate($im, $r, $g, $b);
			
			// Fetch the dimensions of the character being added
			$dimensions = imageftbbox($font_size, $rotation, $font, $string[$i], array());
			$string_width = $dimensions[2] - $dimensions[0];
			$string_height = $dimensions[3] - $dimensions[5];

			// Calculate character offsets
			//$pos_x = $pos_x + $string_width + ($string_width/4);
			$pos_x = $spacing / 4 + $i * $spacing;
			$pos_y = ceil(($img_height-$string_height/2));
			
			if($pos_x + $string_width > $img_width)
			{
				$pos_x = $pos_x - ($pos_x - $string_width);
			}

			// Draw a shadow
			$shadow_x = rand(-3, 3) + $pos_x;
			$shadow_y = rand(-3, 3) + $pos_y;
			$shadow_color = imagecolorallocate($im, $r+20, $g+20, $b+20);
			imagefttext($im, $font_size, $rotation, $shadow_x, $shadow_y, $shadow_color, $font, $string[$i], array());
			
			// Write the character to the image
			imagefttext($im, $font_size, $rotation, $pos_x, $pos_y, $color, $font, $string[$i], array());
		}
		else
		{
			// Get width/height of the character
			$string_width = imagefontwidth(5);
			$string_height = imagefontheight(5);

			// Calculate character offsets
			$pos_x = $spacing / 4 + $i * $spacing;
			$pos_y = $img_height / 2 - $string_height -10 + rand(-3, 3);
			
			// Create a temporary image for this character
			if(gd_version() >= 2)
			{
				$temp_im = imagecreatetruecolor(15, 20);
			}
			else
			{
				$temp_im = imagecreate(15, 20);
			}
			$bg_color = imagecolorallocate($temp_im, 255, 255, 255);
			imagefill($temp_im, 0, 0, $bg_color);
			imagecolortransparent($temp_im, $bg_color);

			// Set the colour
			$r = rand(0, 200);
			$g = rand(0, 200);
			$b = rand(0, 200);
			$color = imagecolorallocate($temp_im, $r, $g, $b);
			
			// Draw a shadow
			$shadow_x = rand(-1, 1);
			$shadow_y = rand(-1, 1);
			$shadow_color = imagecolorallocate($temp_im, $r+50, $g+50, $b+50);
			imagestring($temp_im, 5, 1+$shadow_x, 1+$shadow_y, $string[$i], $shadow_color);
			
			imagestring($temp_im, 5, 1, 1, $string[$i], $color);
			
			// Copy to main image
			imagecopyresized($im, $temp_im, $pos_x, $pos_y, 0, 0, 40, 55, 15, 20);
			imagedestroy($temp_im);
		}
	}
}

/**
 * Obtain the version of GD installed.
 *
 * @return float Version of GD
 */
function gd_version()
{
	static $gd_version;
	
	if($gd_version)
	{
		return $gd_version;
	}
	if(!extension_loaded('gd'))
	{
		return;
	}
	
	ob_start();
	phpinfo(8);
	$info = ob_get_contents();
	ob_end_clean();
	$info = stristr($info, 'gd version');
	preg_match('/\d/', $info, $gd);
	$gd_version = $gd[0];
	
	return $gd_version;
}
?>
 
Last edited:

Corey

I Break Things
Staff member
Messages
34,551
Reaction score
204
Points
63
I'm going to look at changing some PHP stuff tomorrow. Can you hold off until then?
 

Kames

New Member
Messages
66
Reaction score
0
Points
0
Yeah sure,

I'm currently busy coding the front end of the site so the forum can wait for now.
 

Brandon

Former Senior Account Rep
Community Support
Messages
19,181
Reaction score
28
Points
48
Try this:

PHP:
<?php
/**
 * MyBB 1.2
 * Copyright © 2006 MyBB Group, All Rights Reserved
 *
 * Website: http://www.mybboard.net
 * License: http://www.mybboard.net/eula.html
 *
 * $Id: captcha.php 3063 2007-05-15 23:53:07Z chris $
 */

define("IN_MYBB", 1);

define("NO_ONLINE", 1);
require_once "./global.php";

$img_width = 200;
$img_height = 60;

// The following settings are only used for TTF fonts
$min_size = 20;
$max_size = 32;

$min_angle = -30;
$max_angle = 30;

if($mybb->input['imagehash'] == "test")
{
    $imagestring = "MyBB";
}
elseif($mybb->input['imagehash'])
{
    $query = $db->simple_select(TABLE_PREFIX."captcha", "*", "imagehash='".$db->escape_string(strval($mybb->input['imagehash']))."'", array("limit" => 1));
    $regimage = $db->fetch_array($query);
    $imagestring = $regimage['imagestring'];
}
else
{
    return false;
}
    
$ttf_fonts = array();

// We have support for true-type fonts (FreeType 2)
if(function_exists("imagefttext"))
{
    // Get a list of the files in the 'catpcha_fonts' directory
    $ttfdir  = @opendir(MYBB_ROOT."inc/captcha_fonts");
    if($ttfdir)
    {
        while($file = readdir($ttfdir))
        {
            // If this file is a ttf file, add it to the list
            if(is_file(MYBB_ROOT."inc/captcha_fonts/".$file) && get_extension($file) == "ttf")
            {
                $ttf_fonts[] = MYBB_ROOT."inc/captcha_fonts/".$file;
            }
        }
    }
}

// Have one or more TTF fonts in our array, we can use TTF captha's
if(count($ttf_fonts) > 0)
{
    $use_ttf = 1;
}
else
{
    $use_ttf = 0;
}

// Check for GD >= 2, create base image
if(gd_version() >= 2)
{
    $im = imagecreatetruecolor($img_width, $img_height);
}
else
{
    $im = imagecreate($img_width, $img_height);
}

// No GD support, die.
if(!$im)
{
    die("No GD support.");
}

// Fill the background with white
$bg_color = imagecolorallocate($im, 255, 255, 255);
imagefill($im, 0, 0, $bg_color);

// Draw random circles, squares or lines?
$to_draw = rand(0, 2);
if($to_draw == 1)
{
    draw_circles($im);
}
else if($to_draw == 2)
{
    draw_squares($im);
}
else
{
    draw_lines($im);
}

// Draw dots on the image
draw_dots($im);

// Write the image string to the image
draw_string($im, $imagestring);

// Draw a nice border around the image
$border_color = imagecolorallocate($im, 0, 0, 0);
imagerectangle($im, 0, 0, $img_width-1, $img_height-1, $border_color);

// Output the image
header("Content-type: image/png");
imagepng($im);
imagedestroy($im);
exit;

/**
 * Draws a random number of lines on the image.
 *
 * @param resource The image.
 */
function draw_lines(&$im)
{
    global $img_width, $img_height;

    for($i = 10; $i < $img_width; $i += 10)
    {
        $color = imagecolorallocate($im, rand(150, 255), rand(150, 255), rand(150, 255));
        imageline($im, $i, 0, $i, $img_height, $color);
    }
    for($i = 10; $i < $img_height; $i += 10)
    {
        $color = imagecolorallocate($im, rand(150, 255), rand(150, 255), rand(150, 255));
        imageline($im, 0, $i, $img_width, $i, $color);
    }
}

/**
 * Draws a random number of circles on the image.
 *
 * @param resource The image.
 */
function draw_circles(&$im)
{
    global $img_width, $img_height;
    
    $circles = $img_width*$img_height / 100;
    for($i = 0; $i <= $circles; $i++)
    {
        $color = imagecolorallocate($im, rand(180, 255), rand(180, 255), rand(180, 255));
        $pos_x = rand(1, $img_width);
        $pos_y = rand(1, $img_height);
        $circ_width = ceil(rand(1, $img_width)/2);
        $circ_height = rand(1, $img_height);
        imagearc($im, $pos_x, $pos_y, $circ_width, $circ_height, 0, rand(200, 360), $color);
    }
}

/**
 * Draws a random number of dots on the image.
 *
 * @param resource The image.
 */
function draw_dots(&$im)
{
    global $img_width, $img_height;
    
    $dot_count = $img_width*$img_height/5;
    for($i = 0; $i <= $dot_count; $i++)
    {
        $color = imagecolorallocate($im, rand(200, 255), rand(200, 255), rand(200, 255));
        imagesetpixel($im, rand(0, $img_width), rand(0, $img_height), $color);
    }    
}

/**
 * Draws a random number of squares on the image.
 *
 * @param resource The image.
 */
function draw_squares(&$im)
{
    global $img_width, $img_height;
    
    $square_count = 30;
    for($i = 0; $i <= $square_count; $i++)
    {
        $color = imagecolorallocate($im, rand(150, 255), rand(150, 255), rand(150, 255));
        $pos_x = rand(1, $img_width);
        $pos_y = rand(1, $img_height);
        $sq_width = $sq_height = rand(10, 20);
        $pos_x2 = $pos_x + $sq_height;
        $pos_y2 = $pos_y + $sq_width;
        imagefilledrectangle($im, $pos_x, $pos_y, $pos_x2, $pos_y2, $color); 
    }
}

/**
 * Writes text to the image.
 *
 * @param resource The image.
 * @param string The string to be written
 */
function draw_string(&$im, $string)
{
    global $use_ttf, $min_size, $max_size, $min_angle, $max_angle, $ttf_fonts, $img_height, $img_width;
    
    if(empty($string))
    {
        return false;
    }
    
    $spacing = $img_width / my_strlen($string);
    $string_length = my_strlen($string);
    for($i = 0; $i < $string_length; $i++)
    {
        // Using TTF fonts
        if($use_ttf)
        {
            // Select a random font size
            $font_size = rand($min_size, $max_size);
            
            // Select a random font
            $font = array_rand($ttf_fonts);
            $font = $ttf_fonts[$font];
    
            // Select a random rotation
            $rotation = rand($min_angle, $max_angle);
            
            // Set the colour
            $r = rand(0, 200);
            $g = rand(0, 200);
            $b = rand(0, 200);
            $color = imagecolorallocate($im, $r, $g, $b);
            
            // Fetch the dimensions of the character being added
            $dimensions = imageftbbox($font_size, $rotation, $font, $string[$i], array());
            $string_width = $dimensions[2] - $dimensions[0];
            $string_height = $dimensions[3] - $dimensions[5];

            // Calculate character offsets
            //$pos_x = $pos_x + $string_width + ($string_width/4);
            $pos_x = $spacing / 4 + $i * $spacing;
            $pos_y = ceil(($img_height-$string_height/2));
            
            if($pos_x + $string_width > $img_width)
            {
                $pos_x = $pos_x - ($pos_x - $string_width);
            }

            // Draw a shadow
            $shadow_x = rand(-3, 3) + $pos_x;
            $shadow_y = rand(-3, 3) + $pos_y;
            $shadow_color = imagecolorallocate($im, $r+20, $g+20, $b+20);
            imagefttext($im, $font_size, $rotation, $shadow_x, $shadow_y, $shadow_color, $font, $string[$i], array());
            
            // Write the character to the image
            imagefttext($im, $font_size, $rotation, $pos_x, $pos_y, $color, $font, $string[$i], array());
        }
        else
        {
            // Get width/height of the character
            $string_width = imagefontwidth(5);
            $string_height = imagefontheight(5);

            // Calculate character offsets
            $pos_x = $spacing / 4 + $i * $spacing;
            $pos_y = $img_height / 2 - $string_height -10 + rand(-3, 3);
            
            // Create a temporary image for this character
            if(gd_version() >= 2)
            {
                $temp_im = imagecreatetruecolor(15, 20);
            }
            else
            {
                $temp_im = imagecreate(15, 20);
            }
            $bg_color = imagecolorallocate($temp_im, 255, 255, 255);
            imagefill($temp_im, 0, 0, $bg_color);
            imagecolortransparent($temp_im, $bg_color);

            // Set the colour
            $r = rand(0, 200);
            $g = rand(0, 200);
            $b = rand(0, 200);
            $color = imagecolorallocate($temp_im, $r, $g, $b);
            
            // Draw a shadow
            $shadow_x = rand(-1, 1);
            $shadow_y = rand(-1, 1);
            $shadow_color = imagecolorallocate($temp_im, $r+50, $g+50, $b+50);
            imagestring($temp_im, 5, 1+$shadow_x, 1+$shadow_y, $string[$i], $shadow_color);
            
            imagestring($temp_im, 5, 1, 1, $string[$i], $color);
            
            // Copy to main image
            imagecopyresized($im, $temp_im, $pos_x, $pos_y, 0, 0, 40, 55, 15, 20);
            imagedestroy($temp_im);
        }
    }
}

/**
 * Obtain the version of GD installed.
 *
 * @return float Version of GD
 */
function gd_version()
{
    static $gd_version;
    
    if($gd_version)
    {
        return $gd_version;
    }
    if(!extension_loaded('gd'))
    {
        return;
    }
    
    ob_start();
    $info = ob_get_contents();
    ob_end_clean();
    $info = stristr($info, 'gd version');
    preg_match('/\d/', $info, $gd);
    $gd_version = $gd[0];
    
    return $gd_version;
}
?>
</span> </span>
 

Kames

New Member
Messages
66
Reaction score
0
Points
0
Ok, I'll try that out tomorrow, haven't got time now.

Also, What bits have you changed, if you don't mind me asking?
 

Brandon

Former Senior Account Rep
Community Support
Messages
19,181
Reaction score
28
Points
48
I removed the phpinfo(8); towards the bottom.
 

The_Magistrate

New Member
Messages
1,118
Reaction score
0
Points
0
That may be an issue to bring up with the MyBB support forums. We can't help you diagnose a specific problem with the forum code.
 

Kames

New Member
Messages
66
Reaction score
0
Points
0
It's fine, I thought ahead and already asked them. :)
 
Status
Not open for further replies.
Top