--ss-- Posted May 11, 2008 Share Posted May 11, 2008 Well basically I've written the script below to connect to a SQL databse, retrieve a random name for it, with the name it gets an image from an external sites and overlays it ontop of a background then writes the name as a string onto the image and finally outputs it. It was all working fine when all it had to do was get the image, I tried making it write the text but it messed up and now I keep getting errors :/ Any suggestions? <?php header("Content-type: image/gif"); //Info $dbhost = "localhost"; $dbuser = " "; $dbpass = " "; $dbname = " "; //Connect mysql_connect("$dbhost", "$dbuser", "$dbpass"); mysql_select_db("$dbname"); //Random Habbo $random = mysql_query("SELECT name FROM names ORDER BY RAND() LIMIT 1"); $habbo = mysql_fetch_array($random); //Generate Image $text = $habbo[0]; $white = imagecolorallocate($im, 255, 255, 255); $font = volter.ttf; $im = imagecreatefromgif("bg.gif"); $in = imagecreatefromgif("http://www.habbo.co.uk/habbo-imaging/avatarimage?user=$habbo[0]&action=std&direction=4&head_direction=3&gesture=sml&size=l&img_format=gif"); $in_x = imagesx($in); $in_y = imagesy($in); imagecopymerge($im,$in,24,11,0,0,$in_x,$in_y,100); imagettftext($im, 8, 0, 10, 20, $white, $font, $text); imagegif($im); imagedestroy($im); ?> Btw, I know the database info is missing, that's cause I removed it myself. Thanks for reading . Quote Link to comment https://forums.phpfreaks.com/topic/105134-gd-library-help/ Share on other sites More sharing options...
--ss-- Posted May 11, 2008 Author Share Posted May 11, 2008 Bump :/ Quote Link to comment https://forums.phpfreaks.com/topic/105134-gd-library-help/#findComment-538320 Share on other sites More sharing options...
MadTechie Posted May 11, 2008 Share Posted May 11, 2008 $in = imagecreatefromgif("http://www.habbo.co.uk/habbo-imaging/avatarimage?user=$habbo[0]&action=std&direction=4&head_direction=3&gesture=sml&size=l&img_format=gif"); should be $in = imagecreatefromgif("http://www.habbo.co.uk/habbo-imaging/avatarimage?user=$text&action=std&direction=4&head_direction=3&gesture=sml&size=l&img_format=gif"); But without knowing the errors i can't say! Quote Link to comment https://forums.phpfreaks.com/topic/105134-gd-library-help/#findComment-538324 Share on other sites More sharing options...
--ss-- Posted May 11, 2008 Author Share Posted May 11, 2008 $in = imagecreatefromgif("http://www.habbo.co.uk/habbo-imaging/avatarimage?user=$habbo[0]&action=std&direction=4&head_direction=3&gesture=sml&size=l&img_format=gif"); should be $in = imagecreatefromgif("http://www.habbo.co.uk/habbo-imaging/avatarimage?user=$text&action=std&direction=4&head_direction=3&gesture=sml&size=l&img_format=gif"); But without knowing the errors i can't say! Technically it's just the same thing so it doesn't matter but thanks for pointing it out Anyway the error I get is the normal GD Library error off: The image “http://www.shanes.sawhosting.com/php/show.php” cannot be displayed, because it contains errors. I beleive it has nothing to do with the actual two images merging and the first part and it's the text bit which is causing problematic as that's when the error started appearing . Quote Link to comment https://forums.phpfreaks.com/topic/105134-gd-library-help/#findComment-538403 Share on other sites More sharing options...
BlueSkyIS Posted May 11, 2008 Share Posted May 11, 2008 change this // $font = volter.ttf; // WRONG $font = 'volter.ttf'; // Right Quote Link to comment https://forums.phpfreaks.com/topic/105134-gd-library-help/#findComment-538421 Share on other sites More sharing options...
--ss-- Posted May 11, 2008 Author Share Posted May 11, 2008 change this // $font = volter.ttf; // WRONG $font = 'volter.ttf'; // Right Haha should off known it'd be a noob error such as this >.< Thanks a ton! Edit , Fixed it but it still doesn't work Quote Link to comment https://forums.phpfreaks.com/topic/105134-gd-library-help/#findComment-538428 Share on other sites More sharing options...
BlueSkyIS Posted May 11, 2008 Share Posted May 11, 2008 imagecreatefromgif() takes a file name, not a URL. Quote Link to comment https://forums.phpfreaks.com/topic/105134-gd-library-help/#findComment-538438 Share on other sites More sharing options...
--ss-- Posted May 11, 2008 Author Share Posted May 11, 2008 imagecreatefromgif() takes a file name, not a URL. I've used an almost identical script to this in the past where it did the same job of merging two images and it's always worked before though? As I said , I believe that part is fine as it only started messing up when I tried adding text . Quote Link to comment https://forums.phpfreaks.com/topic/105134-gd-library-help/#findComment-538442 Share on other sites More sharing options...
BlueSkyIS Posted May 11, 2008 Share Posted May 11, 2008 ah, that's new info for me. thanks for that. is your font file in the same directory as the script? Quote Link to comment https://forums.phpfreaks.com/topic/105134-gd-library-help/#findComment-538445 Share on other sites More sharing options...
--ss-- Posted May 11, 2008 Author Share Posted May 11, 2008 ah, that's new info for me. thanks for that. is your font file in the same directory as the script? Indeed it is. I'm not sure why this is happening now but when I remove the line to add text the script messed up (Even though it was fine before) Quote Link to comment https://forums.phpfreaks.com/topic/105134-gd-library-help/#findComment-538450 Share on other sites More sharing options...
BlueSkyIS Posted May 11, 2008 Share Posted May 11, 2008 i get an error due to this being in the wrong place: $white = imagecolorallocate($im, 255, 255, 255); ...should be after you define $im. Quote Link to comment https://forums.phpfreaks.com/topic/105134-gd-library-help/#findComment-538451 Share on other sites More sharing options...
BlueSkyIS Posted May 11, 2008 Share Posted May 11, 2008 i also had to put this before imagegif(): header("Content-type: image/gif"); argh, never mind. i missed copying it from your first post.. still working onit. Quote Link to comment https://forums.phpfreaks.com/topic/105134-gd-library-help/#findComment-538452 Share on other sites More sharing options...
BlueSkyIS Posted May 11, 2008 Share Posted May 11, 2008 this works for me: <?php $habbo = "hello world"; //Generate Image $text = $habbo; $font = 'Andale Mono.ttf'; $im = imagecreatefromgif("coloradoflag.gif"); $white = imagecolorallocate($im, 255, 255, 255); $in = imagecreatefromgif("http://www.habbo.co.uk/habbo-imaging/avatarimage?user=$habbo[0]&action=std&direction=4&head_direction=3&gesture=sml&size=l&img_format=gif"); $in_x = imagesx($in); $in_y = imagesy($in); imagecopymerge($im,$in,24,11,0,0,$in_x,$in_y,100); imagettftext($im, 8, 0, 10, 20, $white, $font, $text); header("Content-type: image/gif"); imagegif($im); imagedestroy($im); ?> note my changed font. i don't have the one you used. Quote Link to comment https://forums.phpfreaks.com/topic/105134-gd-library-help/#findComment-538456 Share on other sites More sharing options...
--ss-- Posted May 11, 2008 Author Share Posted May 11, 2008 this works for me: <?php $habbo = "hello world"; //Generate Image $text = $habbo; $font = 'Andale Mono.ttf'; $im = imagecreatefromgif("coloradoflag.gif"); $white = imagecolorallocate($im, 255, 255, 255); $in = imagecreatefromgif("http://www.habbo.co.uk/habbo-imaging/avatarimage?user=$habbo[0]&action=std&direction=4&head_direction=3&gesture=sml&size=l&img_format=gif"); $in_x = imagesx($in); $in_y = imagesy($in); imagecopymerge($im,$in,24,11,0,0,$in_x,$in_y,100); imagettftext($im, 8, 0, 10, 20, $white, $font, $text); header("Content-type: image/gif"); imagegif($im); imagedestroy($im); ?> note my changed font. i don't have the one you used. Yay, now we're getting somewhere: I know get this error instead: Fatal error: Call to undefined function imagettftext() in /home/shanessa/public_html/php/show2.php on line 25 Line 25 being: imagettftext($im, 8, 0, 10, 20, $white, $font, $text); Thanks for all your help so far! Quote Link to comment https://forums.phpfreaks.com/topic/105134-gd-library-help/#findComment-538464 Share on other sites More sharing options...
BlueSkyIS Posted May 11, 2008 Share Posted May 11, 2008 bummer, it looks like you need to recompile PHP with missing truetype support using --with-freetype-dir AND --enable-gd-native-ttf http://us.php.net/imagettftext Quote Link to comment https://forums.phpfreaks.com/topic/105134-gd-library-help/#findComment-538483 Share on other sites More sharing options...
--ss-- Posted May 11, 2008 Author Share Posted May 11, 2008 bummer, it looks like you need to recompile PHP with missing truetype support using --with-freetype-dir AND --enable-gd-native-ttf http://us.php.net/imagettftext I'm guessing my host doesn't have http://www.freetype.org/ installed? Darn , is there a way off getting past this? Quote Link to comment https://forums.phpfreaks.com/topic/105134-gd-library-help/#findComment-538495 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.