patawic Posted November 5, 2009 Share Posted November 5, 2009 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); ?> Link to comment https://forums.phpfreaks.com/topic/180379-imagecreatefrompng-breaks-if-theres-a-space-in-the-url/ Share on other sites More sharing options...
trq Posted November 5, 2009 Share Posted November 5, 2009 Spaces are not valid within a url. Replace them with %20 and you might have more luck. Link to comment https://forums.phpfreaks.com/topic/180379-imagecreatefrompng-breaks-if-theres-a-space-in-the-url/#findComment-951584 Share on other sites More sharing options...
patawic Posted November 5, 2009 Author Share Posted November 5, 2009 even with %20 it still gives the error ive tried str_replace'ing any spaces with %20 and it still doesnt work Link to comment https://forums.phpfreaks.com/topic/180379-imagecreatefrompng-breaks-if-theres-a-space-in-the-url/#findComment-951587 Share on other sites More sharing options...
trq Posted November 5, 2009 Share Posted November 5, 2009 Are these gamer tags under your control? because as I said, urls should not contain spaces. Link to comment https://forums.phpfreaks.com/topic/180379-imagecreatefrompng-breaks-if-theres-a-space-in-the-url/#findComment-951590 Share on other sites More sharing options...
patawic Posted November 5, 2009 Author Share Posted November 5, 2009 http://avatar.xboxlive.com/avatar/I patawic I/avatar-body.png well they are the links to the avatars with spaces in them... they work perfectly Link to comment https://forums.phpfreaks.com/topic/180379-imagecreatefrompng-breaks-if-theres-a-space-in-the-url/#findComment-951595 Share on other sites More sharing options...
trq Posted November 5, 2009 Share Posted November 5, 2009 they work perfectly Most of the time maybe. I'll say it one more time however, url's should not contain spaces. See http://www.ietf.org/rfc/rfc1738.txt Have you tried url_encode on these urls? Link to comment https://forums.phpfreaks.com/topic/180379-imagecreatefrompng-breaks-if-theres-a-space-in-the-url/#findComment-951609 Share on other sites More sharing options...
thebadbad Posted November 5, 2009 Share Posted November 5, 2009 Just run $name through rawurlencode() (as it seems their system doesn't like plus chars). Else, str_replace(' ', '%20', $name) should work fine. Link to comment https://forums.phpfreaks.com/topic/180379-imagecreatefrompng-breaks-if-theres-a-space-in-the-url/#findComment-951632 Share on other sites More sharing options...
patawic Posted November 5, 2009 Author Share Posted November 5, 2009 urlencode() didnt work as it replaces spaces with +'s ill try rawurlencode() EDIT: rawurlencode worked Link to comment https://forums.phpfreaks.com/topic/180379-imagecreatefrompng-breaks-if-theres-a-space-in-the-url/#findComment-952078 Share on other sites More sharing options...
flattened Posted November 5, 2009 Share Posted November 5, 2009 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 Link to comment https://forums.phpfreaks.com/topic/180379-imagecreatefrompng-breaks-if-theres-a-space-in-the-url/#findComment-952100 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.