jaikar Posted March 26, 2008 Share Posted March 26, 2008 hi there, any one have ideas / resources about how to embed text in an image? i have an image of size 400 * 400, and have a dynamic text to be emedded to the center of the image. it seems to be simple, but i really dont know where exactly i can start with. i got some info about imagemagick, but it seems i need server access to set it up on the hosting server which i wont get the access. and also checked the GD, but all i can see was how to create an image, which i am not exactly looking for. can any one please give me info about how to do this. thanks in advance... Link to comment https://forums.phpfreaks.com/topic/97896-embedding-text-in-image/ Share on other sites More sharing options...
soycharliente Posted March 26, 2008 Share Posted March 26, 2008 Maybe using imagettftext()? Link to comment https://forums.phpfreaks.com/topic/97896-embedding-text-in-image/#findComment-500878 Share on other sites More sharing options...
jaikar Posted March 26, 2008 Author Share Posted March 26, 2008 hi there.. thanks for the clue !.. actually it works with images created from php only, but i saw another way .. using imagecreatefromjpeg and imagettftext solved the problem... here is the code... <?php function LoadJpeg($imgname) { $im = @imagecreatefromjpeg($imgname); /* Attempt to open */ if (!$im) { /* See if it failed */ $im = imagecreatetruecolor(150, 30); /* Create a black image */ $bgc = imagecolorallocate($im, 255, 255, 255); $tc = imagecolorallocate($im, 0, 0, 0); imagefilledrectangle($im, 0, 0, 150, 30, $bgc); /* Output an errmsg */ imagestring($im, 1, 5, 5, "Error loading $imgname", $tc); } return $im; } header("Content-Type: image/jpeg"); $im = LoadJpeg("test.jpg"); // here is where you need to point to an existing image on which you need to write the text. // Create the image //$im = imagecreatetruecolor(400, 30); // Create some colors $white = imagecolorallocate($im, 255, 255, 255); $grey = imagecolorallocate($im, 128, 128, 128); $black = imagecolorallocate($im, 0, 0, 0); imagefilledrectangle($im, 0, 0, 399, 29, $white); // The text to draw $text = 'Testing...'; // Replace path by your own font path $font = 'arial.ttf'; // Add some shadow to the text imagettftext($im, 20, 0, 11, 21, $grey, $font, $text); // Add the text imagettftext($im, 20, 0, 10, 20, $black, $font, $text); // Using imagepng() results in clearer text compared with imagejpeg() imagepng($im); imagedestroy($im); imagejpeg($img); ?> Link to comment https://forums.phpfreaks.com/topic/97896-embedding-text-in-image/#findComment-500974 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.