Jump to content

[SOLVED] Problem with gd on linux (2)


Gruzin

Recommended Posts

Hey guys,

 

I have a little security code and it works just fine on windows, but on linux it doesn't creat a new PNG file.

 

here is the code:

<?php
function SecurityCode(){
$num = rand(1000,9999);
header ("Content-type: image/png");
$img_handle = imagecreate (50, 20) or die ("Cannot Create image"); 
$back_color = imagecolorallocate ($img_handle, 255, 255, 255); 
$txt_color = imagecolorallocate ($img_handle, 233, 114, 191); 
imagestring ($img_handle, 31, 7, 2,  $num, $txt_color); 
imagepng ($img_handle,"code.png");
echo "<img src='code.png'>";
}
?>

 

Any help will be greatly appreciated,

George

Link to comment
https://forums.phpfreaks.com/topic/45236-solved-problem-with-gd-on-linux-2/
Share on other sites

erm.. either remove the header or read the file inn,

 

this works fine

 

<?php
function SecurityCode(){
$num = rand(1000,9999);
//header ("Content-type: image/png");
$img_handle = imagecreate (50, 20); 
$back_color = imagecolorallocate ($img_handle, 255, 255, 255); 
$txt_color = imagecolorallocate ($img_handle, 233, 114, 191); 
imagestring ($img_handle, 31, 7, 2,  $num, $txt_color); 
imagepng ($img_handle,"code.png");
echo "<img src='code.png'>";
}

SecurityCode();
?>

 

 

also check you can write to that folder (as i had to update my access rights)

Thanks MadTechie,

 

I've tried it but without no luck, I've added 'Die' function to imagepng and I recieve that error... Think I have to talk to my host about permissions.

 

<?php
function SecurityCode(){
$num = rand(1000,9999);
//header ("Content-type: image/png");
$img_handle = imagecreate (50, 20) or die ("Cannot Create image"); 
$back_color = imagecolorallocate ($img_handle, 255, 255, 255); 
$txt_color = imagecolorallocate ($img_handle, 233, 114, 191); 
imagestring ($img_handle, 31, 7, 2,  $num, $txt_color); 
imagepng ($img_handle,"images/code.png") or die("Cannot save image");
echo "<img src='images/code.png'>";
}
?>

i removed the header and die for testing (something get a few hint when removing them)

 

have you checked the GD lib is installed ?

does it create the code.png file ?

phpinfo();

 

1. Yes, I've checked phpinfo and it is installed (It does creat an image, but doesn't actually save it in directory).

2. No, it doesn't creat a png file (that's my problem).

 

Thanks again,

George

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.