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
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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.