Jump to content

imagecreatefrompng breaks if theres a space in the url


patawic

Recommended Posts

my script is meant to display an xbox live avatar on the image

http://wutwilluchoose.info/xbox/image.php?name=i%20patawic%20i

For some reason it breaks if there are spaces in the gamertag

 

heres my code

<?
$name = $_GET['name'];
$image = imagecreatefrompng("base.png");  
$img = imagecreatetruecolor(imagesx($image), imagesy($image));
$watermark = imagecreatefrompng("http://avatar.xboxlive.com/avatar/$name/avatar-body.png");

$base_width = imagesx($image);
$base_height = imagesy($image);
$watermark_width = imagesx($watermark);  
$watermark_height = imagesy($watermark);

$dest_x = $base_width - $watermark_width - 0;  
$dest_y = $base_height - $watermark_height - 0; 

imagecopy($img, $image, 0, 0, 0, 0, $base_width, $base_height);
imagecopy($img, $watermark, $dest_x, $dest_y, 0, -120, $watermark_width, $watermark_height);

header('content-type: image/png');
imagepng($img);  

imagedestroy($img);  
imagedestroy($image);  
imagedestroy($watermark);

?>

Hey!

 

I had a simlar problem: users would input text, and it would be on a generated image, but it never output more than one word (lest I want an error)

 

Now, I don't know how you have your's set up, but hopefully how I did mine can help you in some sort of way  ;)

 

On the page to output the new url:

$text = $_POST['text']; //Inputted text
$text = str_replace(" ", "+",$text); //text in the url

 

in the url now it's: url.com/image.php?t=file+name

 

then on the page to create the image:

$string = $_GET['t']; //gets what ever is set to "t"
$string = str_replace("+", " ",$string); // replaces "+" with " " (a space) on the image

 

and use $string for the text variable.

 

hope that can help  :)

 

 

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.