steveangelis Posted February 5, 2011 Share Posted February 5, 2011 I am attempting to create an image and I have run into a snag. I want to add both text and another image to the image I am making. Here is the code so far minus unnecessary parts: header ("Content-type: image/png"); $name = $fetch_user['username']; $rank = $fetch_rank['rank_title']; $img_url = 'path''. $fetch_rank['rank_image']; $im = @imagecreatefrompng("$img_url") or die("Cannot Initialize new GD image stream"); // try changing this as well $font = 4; $width = imagefontwidth($font) * strlen($string) ; $height = imagefontheight($font) ; $im = imagecreatefrompng("image.png"); $x = imagesx($im) - $width ; $y = imagesy($im) - $height; $backgroundColor = imagecolorallocate ($im, 255, 255, 255); $textColor = imagecolorallocate ($im, 255, 255, 255); //imagestring ($im, $font, $x, $y, $string, $textColor); imagestring ($im, $font, 100, 10, $name, $textColor); imagestring ($im, $font, 100, 22, $rank, $textColor); imagepng($im); Everything works UNTIL I added in this part: $im = @imagecreatefrompng("$img_url") or die("Cannot Initialize new GD image stream"); Any idea what I am doing wrong? All that comes up is "Cannot Initialize new GD image stream"; and I know the URL's work. Link to comment https://forums.phpfreaks.com/topic/226756-image-creation/ Share on other sites More sharing options...
sottwell Posted February 5, 2011 Share Posted February 5, 2011 I'm not sure it will make a difference, but you don't need the quotes surrounding the $img_url variable. Link to comment https://forums.phpfreaks.com/topic/226756-image-creation/#findComment-1170197 Share on other sites More sharing options...
litebearer Posted February 5, 2011 Share Posted February 5, 2011 is the source image a png? Link to comment https://forums.phpfreaks.com/topic/226756-image-creation/#findComment-1170210 Share on other sites More sharing options...
litebearer Posted February 5, 2011 Share Posted February 5, 2011 This has been tested and works. Make appropriate modifications for your particular use. <?PHP header ("Content-type: image/png"); /* IMAGE TO USE AS BACKGROUND */ $source_image = "road000.png"; /* IMAGE TO OVERLAY ON BACKGROUND */ $overlay_image = "road001.png"; /* CREATE TEMPORARY BACKGROUND */ $background = imagecreatefrompng($source_image); /* CREATE TEMPORARY OVERLAY IMAGE */ $insert = imagecreatefrompng($overlay_image); /* GET OVERLAY IMAGE WIDTH AND HEIGHT */ $insert_x = imagesx($insert); $insert_y = imagesy($insert); /* SET WHERE YOU WANT TO PLACE OVERLAY ON BACKGROUND */ /* FOR THIS EXAMPLE WE WILL USE 100 FROM LEFT AND TOP EDGES */ $set_x = 100; $set_y = 100; /* COMBINE THE IMAGES INTO A SINGLE OUTPUT IMAGE */ imagecopymerge($background,$insert,$set_x,$set_y,0,0,$insert_x,$insert_y,100); /* OUTPUT THE RESULTS */ imagepng($background); ?> Link to comment https://forums.phpfreaks.com/topic/226756-image-creation/#findComment-1170215 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.