Jump to content

[SOLVED] trying to generate thumbnail


rondog

Recommended Posts

Hi I am calling a php file in my img src tag to generate a thumbnail, but it doesnt seem to be working:\

 

the img src tag:

<img src=createphotothumb.php?source=photos/".$row['filename'].">

 

createphotothumb.php

<?php
header("Content-type: image/jpeg");
$photofile = $_GET['source'];

$img = imagecreatefromjpeg( $photofile );
$width = imagesx( $img );
$height = imagesy( $img );

$new_width = 150;
$new_height = floor( $height * ( $thumbWidth / $width ) );

$tmp_img = imagecreatetruecolor( $new_width, $new_height );

imagecopyresized( $tmp_img, $img, 0, 0, 0, 0, $new_width, $new_height, $width, $height );

imagejpeg( $tmp_img, $mkThumbFile,40 );
imagedestroy($tmp_img);
?>

 

When I right click where the image is suppose to be, the properties say its:

http://dopserv1.com/hosted/army/createphotothumb.php?source=photos/img_2602.jpg

so it is reading from the DB..any ideas?

Link to comment
Share on other sites

Your php script looks fine as far as I can tell (its late here though, so that may not be very far). I think the problem is in your tag.

 

Can you post some code from before (and including) the image tag? Something is strange there.

Link to comment
Share on other sites

Well this is the whole line that is suppose to output the image:

<?php
echo "<td><div id=\"$row[id]-$row[name]\"><a href=\"?gid=$gid&sid=$sid&segid=$row[segment_id]&pic=$row[id]\"><img src=\"createphotothumb.php?source=photos/".$row['filename']."\"></a></div></td>\n";
?>

 

and then the createphotothumb.php file:

<?php
header("Content-type: image/jpeg");
$photofile = $_GET['source'];

$img = imagecreatefromjpeg( $photofile );

$width = imagesx( $img );
$height = imagesy( $img );

$new_width = 150;
$new_height = floor( $height * ( $thumbWidth / $width ) );

$tmp_img = imagecreatetruecolor( $new_width, $new_height );

imagecopyresized( $tmp_img, $img, 0, 0, 0, 0, $new_width, $new_height, $width, $height );

imagejpeg( $tmp_img, $mkThumbFile,40 );
imagedestroy($tmp_img);
?>

Link to comment
Share on other sites

Another guy on the forums was having the exact same problem. I took his code and put it on my box and it worked fine. Might be an operating system problem or a webserver problem. I am using Windows XP Pro with IIS and php 5.1.2.

 

try just outputting the image instaed of saving it which is what you look like your doing

imagejpeg($tmp_img);

 

Ray

Link to comment
Share on other sites

ok I tried that and same thing. I dont think its a server thing because I have another createthumb.php file converting an FLV to a jpg and it works fine. I am doing the same exact process basically.

 

http://dopserv1.com/hosted/army/createthumb.php?source=videos/1207354947a3-t9-001.flv

 

see how that works??

 

thats using this code:

<?php
header("Content-type: image/jpeg");
$moviefile = $_GET['source'];
$mov = new ffmpeg_movie($moviefile,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();
imagejpeg($newImg,$mkThumbFile,40);
imagedestroy($newImg);
?>

Link to comment
Share on other sites

Ok I managed to figure it out!!

 

I changed:

<?php
$new_height = floor($height * ($thumbWidth / $width));

to

$new_height = floor($height * ($new_width / $width));
?>

 

I didnt realized $thumbWidth was undefined.

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.