DeanWhitehouse Posted August 13, 2008 Share Posted August 13, 2008 I have this code <?php /* put ONLY this code into a file called image.php put a image called "myimage.jpg" info the same folder then open image.php */ if(isset($_GET['date'])) { $date = $_GET['date']; $first = $_GET['first']; $last = $_GET['last']; $id = $_GET['id']; $pfirst = $_GET['pfirst']; $plast = $_GET['plast']; $imgname = "discount.jpg"; $im = imagecreatefromjpeg($imgname); $tc = imagecolorallocate($im, 0, 0, 0); //imagestring($im, 1, 5, 5, "Details", $tc); imagestring($im,5,50,100,"Date:".$date,$tc); header("Content-Type: image/jpeg"); imagejpeg($im); } ?> and the image is produced fine, but the font style looks horrible, and from what i read on the PHP manual you need to upload a font file to change it , is there a way i can just use a font e.g. ariel? Quote Link to comment https://forums.phpfreaks.com/topic/119499-solved-image-gd-apply-font/ Share on other sites More sharing options...
DarkWater Posted August 13, 2008 Share Posted August 13, 2008 You'd use the imagettftext file and put arial.ttf in the same folder. Quote Link to comment https://forums.phpfreaks.com/topic/119499-solved-image-gd-apply-font/#findComment-615622 Share on other sites More sharing options...
DeanWhitehouse Posted August 13, 2008 Author Share Posted August 13, 2008 hmm, do you know where i can get ariel.ttf? or any other fonts, i was hoping to do it without having to download them. Quote Link to comment https://forums.phpfreaks.com/topic/119499-solved-image-gd-apply-font/#findComment-615623 Share on other sites More sharing options...
DarkWater Posted August 13, 2008 Share Posted August 13, 2008 You can check in your font directory, or you can just go dafont.com and download basically any font you can think of and then some. xD Quote Link to comment https://forums.phpfreaks.com/topic/119499-solved-image-gd-apply-font/#findComment-615624 Share on other sites More sharing options...
DeanWhitehouse Posted August 13, 2008 Author Share Posted August 13, 2008 Ok, awesome thanks, Quote Link to comment https://forums.phpfreaks.com/topic/119499-solved-image-gd-apply-font/#findComment-615625 Share on other sites More sharing options...
DeanWhitehouse Posted August 13, 2008 Author Share Posted August 13, 2008 this code doesnt work i get an error message saying there is an error. <?php // Set the content-type header("Content-type: image/png"); // Create the image $im = imagecreatefromjpeg($imgname); $tc = imagecolorallocate($im, 0, 0, 0); // 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, $tc, $font, $text); // Using imagepng() results in clearer text compared with imagejpeg() imagepng($im); imagedestroy($im); ?> Quote Link to comment https://forums.phpfreaks.com/topic/119499-solved-image-gd-apply-font/#findComment-615635 Share on other sites More sharing options...
DarkWater Posted August 13, 2008 Share Posted August 13, 2008 What kind of error...? Quote Link to comment https://forums.phpfreaks.com/topic/119499-solved-image-gd-apply-font/#findComment-615638 Share on other sites More sharing options...
DeanWhitehouse Posted August 13, 2008 Author Share Posted August 13, 2008 that is what it says, The image 'mysite url' cannot be displayed, because it contains errors. Quote Link to comment https://forums.phpfreaks.com/topic/119499-solved-image-gd-apply-font/#findComment-615640 Share on other sites More sharing options...
DeanWhitehouse Posted August 13, 2008 Author Share Posted August 13, 2008 update on the code <?php // Set the content-type header("Content-type: image/png"); // Create the image $imgname = "discount.jpg"; $im = imagecreatefromjpeg($imgname); $tc = imagecolorallocate($im, 0, 0, 0); // The text to draw $text = 'Testing...'; // Replace path by your own font path $font = 'arial.ttf'; // Add the text imagettftext($im, 20, 0, 10, 20, $tc, $font, $text); // Using imagepng() results in clearer text compared with imagejpeg() imagepng($im); imagedestroy($im); ?> still getting error though Solved now ,it was the shadow bit Quote Link to comment https://forums.phpfreaks.com/topic/119499-solved-image-gd-apply-font/#findComment-615654 Share on other sites More sharing options...
DeanWhitehouse Posted August 13, 2008 Author Share Posted August 13, 2008 Ok, another problem , how can i save the created image? or something because when i print the page , the image isnt there and i need it to be , any ideas? Quote Link to comment https://forums.phpfreaks.com/topic/119499-solved-image-gd-apply-font/#findComment-615685 Share on other sites More sharing options...
DarkWater Posted August 13, 2008 Share Posted August 13, 2008 You can save it by passing another parameter to imagejpeg(). Read the manual on it, and you'll see that the second parameter saves the file. Quote Link to comment https://forums.phpfreaks.com/topic/119499-solved-image-gd-apply-font/#findComment-615687 Share on other sites More sharing options...
DeanWhitehouse Posted August 13, 2008 Author Share Posted August 13, 2008 Soz, that wasnt the prob,it was because the person has another CSS for the print and it mucks it up. Quote Link to comment https://forums.phpfreaks.com/topic/119499-solved-image-gd-apply-font/#findComment-615694 Share on other sites More sharing options...
DarkWater Posted August 13, 2008 Share Posted August 13, 2008 Lol, okay. Quote Link to comment https://forums.phpfreaks.com/topic/119499-solved-image-gd-apply-font/#findComment-615696 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.