Hi,
I can verify that the GD_Lib (used for generating images) is installed
( and working ) with
<?PHP print_r(gd_info()); ?>
on this server - so that is not the problem -
The problem comes in when I want to draw an image using the GD-Lib.
(this example works on my linux box at home but refuses to work on this server )
CODE START -----------------------------------------------
<?PHP
error_reporting(E_ALL ^ E_NOTICE);
/*
simplepng.php
Generates a 50 x 50 pixel png of the color passed in parameter 'color'
*/
// convert guaranteed valid hex value to array of integers
$imColor = hex2int(validHexColor($_REQUEST['color']));
// Step 1. Create a new blank image
$im = imageCreate(50,50);
// Step 2. Set background to 'color'
$background = imageColorAllocate($im, $imColor['r'], $imColor['g'], $imColor['b']);
// Step 3. Send the headers (at last possible time)
header('Content-type: image/png');
// Step 4. Output the image as a PNG
imagePNG($im);
// Step 5. Delete the image from memory
imageDestroy($im);
/**
* @param $hex string 6-digit hexadecimal color
* @return array 3 elements 'r', 'g', & 'b' = int color values
* @desc Converts a 6 digit hexadecimal number into an array of
* 3 integer values ('r' => red value, 'g' => green, 'b' => blue)
*/
function hex2int($hex) {
return array( 'r' => hexdec(substr($hex, 0, 2)), // 1st pair of digits
'g' => hexdec(substr($hex, 2, 2)), // 2nd pair
'b' => hexdec(substr($hex, 4, 2)) // 3rd pair
);
}
/**
* @param $input string 6-digit hexadecimal string to be validated
* @param $default string default color to be returned if $input isn't valid
* @return string the validated 6-digit hexadecimal color
* @desc returns $input if it is a valid hexadecimal color,
* otherwise returns $default (which defaults to black)
*/
function validHexColor($input = '000000', $default = '000000') {
// A valid Hexadecimal color is exactly 6 characters long
// and eigher a digit or letter from a to f
return (eregi('^[0-9a-f]{6}$', $input)) ? $input : $default ;
}
?>
CODE END ---------------------------
Any suggestions ?
Cheers,
Nick.
I can verify that the GD_Lib (used for generating images) is installed
( and working ) with
<?PHP print_r(gd_info()); ?>
on this server - so that is not the problem -
The problem comes in when I want to draw an image using the GD-Lib.
(this example works on my linux box at home but refuses to work on this server )
CODE START -----------------------------------------------
<?PHP
error_reporting(E_ALL ^ E_NOTICE);
/*
simplepng.php
Generates a 50 x 50 pixel png of the color passed in parameter 'color'
*/
// convert guaranteed valid hex value to array of integers
$imColor = hex2int(validHexColor($_REQUEST['color']));
// Step 1. Create a new blank image
$im = imageCreate(50,50);
// Step 2. Set background to 'color'
$background = imageColorAllocate($im, $imColor['r'], $imColor['g'], $imColor['b']);
// Step 3. Send the headers (at last possible time)
header('Content-type: image/png');
// Step 4. Output the image as a PNG
imagePNG($im);
// Step 5. Delete the image from memory
imageDestroy($im);
/**
* @param $hex string 6-digit hexadecimal color
* @return array 3 elements 'r', 'g', & 'b' = int color values
* @desc Converts a 6 digit hexadecimal number into an array of
* 3 integer values ('r' => red value, 'g' => green, 'b' => blue)
*/
function hex2int($hex) {
return array( 'r' => hexdec(substr($hex, 0, 2)), // 1st pair of digits
'g' => hexdec(substr($hex, 2, 2)), // 2nd pair
'b' => hexdec(substr($hex, 4, 2)) // 3rd pair
);
}
/**
* @param $input string 6-digit hexadecimal string to be validated
* @param $default string default color to be returned if $input isn't valid
* @return string the validated 6-digit hexadecimal color
* @desc returns $input if it is a valid hexadecimal color,
* otherwise returns $default (which defaults to black)
*/
function validHexColor($input = '000000', $default = '000000') {
// A valid Hexadecimal color is exactly 6 characters long
// and eigher a digit or letter from a to f
return (eregi('^[0-9a-f]{6}$', $input)) ? $input : $default ;
}
?>
CODE END ---------------------------
Any suggestions ?
Cheers,
Nick.
