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
https://forums.phpfreaks.com/topic/101412-solved-trying-to-generate-thumbnail/
Share on other sites

.$row['filename'].

 

Try taking away that second period.

 

nope that broke my script when I did that :-/

 

I notice if you go directly to

 

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

 

it outputs text rather than an image. So their is something wrong with my createphotothumb.php file

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);
?>

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

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);
?>

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.