Luigi987 Posted July 5, 2010 Share Posted July 5, 2010 Hello, I'm having trouble with my PHP script. I'm trying to get it to read text from a separate .txt file to display in a php dynamic PNG image. The code for it is here: <?php $image = ImageCreateFromPNG("base.png"); $color = imagecolorallocate($image, 0xFF, 0xFF, 0xFF); $colorShadow = imagecolorallocate($image, 0x66, 0x66, 0x66); $font = 'start.ttf'; $fontSize = "6"; $fontRotation = "0"; $str = "[Text read from file goes here]"; /* Shadow */ ImageTTFText($image, $fontSize, $fontRotation, 7, 22, $colorShadow, $font, $str); /* Top Level */ ImageTTFText($image, $fontSize, $fontRotation, 5, 20, $color, $font, $str); header("Content-Type: image/PNG"); ImagePng ($image); imagedestroy($image); ?> I need to somehow get the text from the txt file to be read and used in the [Text read from file goes here] part. Any help is appreciated. Link to comment https://forums.phpfreaks.com/topic/206775-help-with-external-txt-files-being-read-into-php-dynamic-images/ Share on other sites More sharing options...
kenrbnsn Posted July 5, 2010 Share Posted July 5, 2010 You showed us everything except how you're trying to read the file. Ken Link to comment https://forums.phpfreaks.com/topic/206775-help-with-external-txt-files-being-read-into-php-dynamic-images/#findComment-1081340 Share on other sites More sharing options...
Luigi987 Posted July 5, 2010 Author Share Posted July 5, 2010 Well, anything that will get the contents of the text file read into the $str array and displayed on the image is all I need. Link to comment https://forums.phpfreaks.com/topic/206775-help-with-external-txt-files-being-read-into-php-dynamic-images/#findComment-1081342 Share on other sites More sharing options...
kenrbnsn Posted July 5, 2010 Share Posted July 5, 2010 There are many ways in PHP to read a file: fread fgets file file_get_contents Have you looked at any of these? I would use file_get_contents, but you should look at each one to learn how each could be used. <?php $str = trim(file_get_contents('thefilename.here')); ?> Ken Link to comment https://forums.phpfreaks.com/topic/206775-help-with-external-txt-files-being-read-into-php-dynamic-images/#findComment-1081348 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.