[PHP] GD image variables ?

Joined
May 30, 2008
Messages
558
Reaction score
64
okay, so im still learning in GD n stuff

I need the image to be a variable so I can change the image in the database like so i can make it set the image from an egg to anything by choosing between 2 image names in the database from using 2 time stamps like one is when it was made and the second when it should be hatched, so yeah i seem to have this working

PHP:
<?php

$imagename = "egg.png";

function LoadPNG($imgname)
{
    $im = @imagecreatefrompng($imgname);
    return $im;
}

header('Content-Type: image/png');

$img = LoadPNG('egg.png');

$tc  = imagecolorallocate($img, 255, 255, 255);
$tc2  = imagecolorallocate($img, 255,0,0);
imagestring($img, 1, 5, 5, "http://Krazey-Gaming.net/". $imgname, $tc);

imagepng($img);
imagedestroy($img);

?>

but when I try a variable as the image name like

PHP:
<?php

$icon = "egg.png";

$imagename = "$icon";

function LoadPNG($imgname)
{
    $im = @imagecreatefrompng($imgname);
    return $im;
}

header('Content-Type: image/png');

$img = LoadPNG('$icon');

$tc  = imagecolorallocate($img, 255, 255, 255);
$tc2  = imagecolorallocate($img, 255,0,0);
imagestring($img, 1, 5, 5, "http://Krazey-Gaming.net/". $imgname, $tc);

imagepng($img);
imagedestroy($img);

?>

it doesnt work :( any help ?
 
PHP:
<?php 

$icon = "egg.png"; 

$imagename = $icon; //Does removing the quotes work? 

function LoadPNG($imgname) 
{ 
    $im = @imagecreatefrompng($imgname); 
    return $im; 
} 

header('Content-Type: image/png'); 

$img = LoadPNG('$icon'); 

$tc  = imagecolorallocate($img, 255, 255, 255); 
$tc2  = imagecolorallocate($img, 255,0,0); 
imagestring($img, 1, 5, 5, "http://Krazey-Gaming.net/". $imgname, $tc); 

imagepng($img); 
imagedestroy($img); 

?>
 
PHP:
<?php 
// Try This

$icon = "egg.png"; 

$imgname = $icon; 

function LoadPNG($imgname) 
{ 
    $im = @imagecreatefrompng($imgname); 
    return $im; 
} 

header('Content-Type: image/png'); 

$img = LoadPNG('$icon'); 

$tc  = imagecolorallocate($img, 255, 255, 255); 
$tc2  = imagecolorallocate($img, 255,0,0); 
imagestring($img, 1, 5, 5, "http://Krazey-Gaming.net/". $imgname, $tc); 

imagepng($img); 
imagedestroy($img); 

?>
 
Back