Jump to content

Problem with imagejpeg and headers


rondog

Recommended Posts

I am using ffmpeg-php to create thumbnails from flv files. The issue I am having is a header problem. The code to make the jpeg is in a while loop that is drawing from a database. The problem is, their is no header attached to this jpeg so the output is a bunch of weird characters:

�����JFIF���������;CREATOR: gd-jpeg v1.0 (using IJG JPEG v62), quality = 40 ���C� 2!=,.$2I@LKG@FEPZsbPUmVEFd�emw{���N`���}�s~�|���C;!!;|SFS||||||||||||||||||||||||||||||||||||||||||||||||||����V��"�������������� �������}�!1AQa"q2���#B��R��$3br� %&'()*456789:CDEFGHIJSTUVWXYZcdefghijstuvwxyz����������������������������������������������������������������������������������� ������w�!1AQaq"2�B���� #3R�br

 

etc etc...

 

How do I apply headers to this code block so it doesn't do that??

<?php
while($row = mysql_fetch_array($sql)) {
	//$desc = substr($row[description], 0, 200);
	$mov = new ffmpeg_movie("videos/$row[filename]",false);
	$img = $mov->getFrame(50);
	$showImg = $img->toGDImage();
	$mkNewImg = new ffmpeg_frame($showImg);

	$maxWid = 150;
	$oldWid = $mkNewImg->getWidth();
	$oldHgt = $mkNewImg->getHeight();
	$movRatio = $oldWid/$oldHgt;

	if($oldWid > $maxWid) {
		$newWid = $maxWid;
	}

	$newHgt = $newWid / $movRatio;

	$mkNewImg->resize($newWid,$newHgt);
	$newImg = $mkNewImg->toGDImage();
	$displayMe = header("Content-type: image/jpeg");
	$displayMe .= imagejpeg($newImg, $mkThumbFile,40);
	imagedestroy($newImg);
	$count += 1;
	if($count == $columnLimit) {
		echo "<td><div id=\"$row[id]-$row[name]\">$displayme</div></td>\n";
		echo "</tr>\n<tr>\n";
		$count = 0;
	} else {
		echo "<td><div id=\"$row[id]-$row[name]\">$displayme</div></td>\n";
	}
}
?>

 

you can see I am trying to do the headers with these two lines but its not working:

	$displayMe = header("Content-type: image/jpeg");
	$displayMe .= imagejpeg($newImg, $mkThumbFile,40);

 

any ideas?

Link to comment
https://forums.phpfreaks.com/topic/96213-problem-with-imagejpeg-and-headers/
Share on other sites

Your header shouldn't be in any kind of a html tag it is strickly php. To be honest I think you should have the script that creates the thumbnails in it's own page, Then call the script in the loop.

 

echo "<td><div id=\"$row[id]-$row[name]\"><img src=createthumb.php></div></td>\n";

 

GD is not going to work creating multiple images on the same page, by putting the script on another page it creates the image and it's done, then gets called on again. You can always put the link to the movie in the src

 

echo "<td><div id=\"$row[id]-$row[name]\"><img src=createthumb.php?source=videos/".$row['filename']."></div></td>\n";

 

Then in your script you can grab the variable

 

$moviefile = $_GET['source'];
$mov = new ffmpeg_movie("$moviefile",false);

 

What I am saying is don't create the image in your loop, call for the image from another page in the loop.

 

Ray

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.