Jump to content

Help with external .txt files being read into php dynamic images


Luigi987

Recommended Posts

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.

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.