Why no Text after image 1?

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
I put together a script from a bunch of papges from php.net and don't
understand why I get what I expect from the first image but not the
subsequent ones. Expecting a dark grey background with some tect
written and then it saves as a jpg.

I'm taking some old security tapes and breaking them into ten minute
clips. The jpegs from this script will be inrto scenes for my clips.
Made a csv from excel because the dates are mostly weekdays and have a
list in excel already. With that list I know I will have 4 two hour
tapes or 48 ten minute clips and can crank out a csv easy. That and
wanted to see if I could get a csv imprt to work.

Why is there no text fo pictures 2-48??? Part 1 is great. Shouldn't
imagedestroy clear everything or is it in the wrong spot?

I would really like to use imagettftext but could not for the life of
me figure out how to measure the string from the examples on the page.

Thanks for any help!

Here is my code:

$row = 1;
if (($handle = fopen("Part1_48.csv", "r")) !== FALSE) {
    while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
       $num = count($data);
       // echo "<p> $num fields in line $row: <br /></p>\n";
        for ($c=0; $c < $num; $c++) {
            //echo nl2br($data[$c]);

            header("Content-type: image/jpeg");
            $width = 640;
            $height = 480;
            $picture = imagecreate($width,$height);
            $background = imagecolorallocate($picture, 51, 51, 51);
            $text_color = ImageColorAllocate ($picture, 255, 255, 255);
            $TextLine1 = "This is the First Line";
            $TextLine2 = "Second Line";
            $TextLine3 = "Put Date of Tape Here";
            $TextLine4 = $data[$c];
            // Line 1
            $font_size = 5;
            $text_width = imagefontwidth($font_size)*strlen($TextLine1);
            $center = ceil($width / 2);
            $x = $center - (ceil($text_width/2));
            $y = $y + 50;
            imagestring($picture, $font_size, $x , $y, $TextLine1, $text_color);
            // Line 2
            $font_size = 5;
            $text_width = imagefontwidth($font_size)*strlen($TextLine2);
            $center = ceil($width / 2);
            $x = $center - (ceil($text_width/2));
            $y = $y + 50;
            imagestring($picture, $font_size, $x , $y, $TextLine2, $text_color);
            // Line 3
            $font_size = 5;
            $text_width = imagefontwidth($font_size)*strlen($TextLine3);
            $center = ceil($width / 2);
            $x = $center - (ceil($text_width/2));
            $y = $y + 50;
            imagestring($picture, $font_size, $x , $y, $TextLine3, $text_color);
            // Line 4
            $font_size = 5;
            $text_width = imagefontwidth($font_size)*strlen($TextLine4);
            $center = ceil($width / 2);
            $x = $center - (ceil($text_width/2));
            $y = $y + 50;
            imagestring($picture, $font_size, $x , $y, $TextLine4, $text_color);
            imageJPEG($picture,"images/".$TextLine4.".jpg", 100);

Re: Why no Text after image 1?

Quoted text here. Click to load it


Guess that was the culprit and it only took an hour to find.

All the images have text now. Also made the same script create .png's
to see if they looked better. Were twice as big but the jpeg's looked

Site Timeline