<?php
$img_width=200;
$img_height=100;
if(gd_version() >= 2)
{
$im = imagecreatetruecolor($img_width, $img_height);
}
else
{
$im = imagecreate($img_width, $img_height);
}
$bg_color = imagecolorallocate($im, 255, 255, 255);
imagefill($im, 0, 0, $bg_color);
// Output the image
header("Content-type: image/png");
imagepng($im);
imagedestroy($im);
exit;
function gd_version()
{
static $gd_version;
if($gd_version)
{
return $gd_version;
}
if(!extension_loaded('gd'))
{
return;
}
if(function_exists("gd_info"))
{
$gd_info = gd_info();
preg_match('/\d/', $gd_info['GD Version'], $gd);
$gd_version = $gd[0];
}
else
{
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;
}
Try my latest code. Sorry I am not at home so I don't have a server to test the code on.
(2008-10-31, 05:38 PM)DennisTT Wrote: [ -> ]<?php
$img_width=200;
$img_height=100;
if(gd_version() >= 2)
{
$im = imagecreatetruecolor($img_width, $img_height);
}
else
{
$im = imagecreate($img_width, $img_height);
}
$bg_color = imagecolorallocate($im, 255, 255, 255);
imagefill($im, 0, 0, $bg_color);
// Output the image
header("Content-type: image/png");
imagepng($im);
imagedestroy($im);
exit;
function gd_version()
{
static $gd_version;
if($gd_version)
{
return $gd_version;
}
if(!extension_loaded('gd'))
{
return;
}
if(function_exists("gd_info"))
{
$gd_info = gd_info();
preg_match('/\d/', $gd_info['GD Version'], $gd);
$gd_version = $gd[0];
}
else
{
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;
}
(2008-10-31, 09:34 PM)DennisTT Wrote: [ -> ]Try my latest code. Sorry I am not at home so I don't have a server to test the code on.
(2008-10-31, 05:38 PM)DennisTT Wrote: [ -> ]<?php
$img_width=200;
$img_height=100;
if(gd_version() >= 2)
{
$im = imagecreatetruecolor($img_width, $img_height);
}
else
{
$im = imagecreate($img_width, $img_height);
}
$bg_color = imagecolorallocate($im, 255, 255, 255);
imagefill($im, 0, 0, $bg_color);
// Output the image
header("Content-type: image/png");
imagepng($im);
imagedestroy($im);
exit;
function gd_version()
{
static $gd_version;
if($gd_version)
{
return $gd_version;
}
if(!extension_loaded('gd'))
{
return;
}
if(function_exists("gd_info"))
{
$gd_info = gd_info();
preg_match('/\d/', $gd_info['GD Version'], $gd);
$gd_version = $gd[0];
}
else
{
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;
}
Ok Dennys. The change is done. Go to the url.
Ok now change
$bg_color = imagecolorallocate($im, 255, 255, 255);
imagefill($im, 0, 0, $bg_color);
to this:
$bg_color = imagecolorallocate($im, 255, 255, 255);
if($bg_color === false || $bg_color == -1)
{
die('imagecolorallocate failed');
}
$test = imagefill($im, 0, 0, $bg_color);
if(!$test)
{
die('imagefill failed');
}
Ok now change
$bg_color = imagecolorallocate($im, 255, 255, 255);
to
$bg_color = imagecolorallocate($im, 255, 0, 0);
Then it should become a red box.
Done! But the image is still black