FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


problem creating on-the-fly jpeg thumbnails





blackbart
I am doing some work for a motorcycle shop that wants to display clickable thumbnails on their gallery page. I've set up a dir - category relationship and they can create directories on the fly and upload pics to that category.
The scrip then searches the main gallery dir lists all the Directories in it as categories then iterates through the dirs to collect all jpg files and displays a thumbnail image for clicking.
This is easy to do with the "width' and 'height' attributes of the '<img' tag. It is extremely slow though as the directories grow in size.
I have created this bit of code in the main gallery script
Code:
print("<td><a href=\"$base_image\"><img src=\"thumbs.php?image=$base_image\" alt=\"Powder Coat $print_cat\" /></a></td>\n");

and the code in 'thumbs.php:
Code:

<?php
$base_image   =   $_GET['image'];

list($width, $height) = getimagesize("$base_image");
$multiplier   =   100/$width;
$new_width   =   $width * $multiplier;
$new_height   =   $height * $multiplier;
$thumb      =   imagecreatetruecolor($new_width, $new_height);
$source      =   imagecreatefromjpeg("$base_image");

imagecopyresized($thumb, $source, 0,0,0,0, $new_width, $new_height, $width, $height);
header('Content-type: image/jpeg');
imagejpeg($thumb);
imagedestroy($thumb);
?>

no errors, the page executes nicely and quick but I am not rendering any images on the page. I can inject this code in between the '<a href=blah>' & '<./a>' without the header and I get the jpeg code displayed as a link. The code is finding the file obiviously, but I ainlt gettin' no image.
Anyone with an idea why?
It is not on a Frihost server. The server has the right version of GD on it. I checked it with this line in my code
vardump(gd_info());
Output:
Quote:

array(11) {
["GD Version"]=> string(27) "bundled (2.0.28 compatible)"
["FreeType Support"]=> bool(true)
["FreeType Linkage"]=> string(13) "with freetype"
["T1Lib Support"]=> bool(false)
["GIF Read Support"]=> bool(true)
["GIF Create Support"]=> bool(true)
["JPG Support"]=> bool(true)
["PNG Support"]=> bool(true)
["WBMP Support"]=> bool(true)
["XBM Support"]=> bool(true)
["JIS-mapped Japanese Font Support"]=> bool(false)
}

Anyone gotta clue?
kv
I am not sure of the problem, but there is one more error in your code

Code:
$multiplier   =   100/$width;


should have been

Code:
$multiplier   =   $width/100;
blackbart
Quote:


I am not sure of the problem, but there is one more error in your code

Code:
$multiplier = 100/$width;

should have been

Code:
$multiplier = $width/100;


No actually it's exactly as i want it. if I want the thumbs to be 100px wide and maintain aspect ratio, I would divide by 100. using the product to then multiply against the height giving me the aspect ratio.
I checked by outputting the $new_width and $new_height vars. Really several way to do the math. My math is good. your's would be too if we then changed the math op on the original file.
If I do it your way I would then have to divide... Six o' one, half-dozen of the other really...
Still workin on this... Can't seem to see a prob with the code. SHould execute. It's a very simple text-book PHP manual implementation. I do get a Jpeg data streem when implementing the function directly. absolutely nothing when called in the manner quoted above.
Maybe this is an Apache handler issue?
*starts diggin through the manual*
blackbart
Well, knock me down and call me stupid. I'm not real sure how it came about but by commmenting out the "header(Content type: image/jpeg);' statement the thing works as planned.
little reading of the Apache manual led me to belive that it wasn;t really necessary so there ya are!
Final code for the function/file
Code:

<?php
$base_image   =   $_GET['image'];
list($width, $height) = getimagesize("$base_image");
$multiplier   =   100/$width;
$new_width   =   $width * $multiplier;
$new_height   =   $height * $multiplier;
$thumb      =   imagecreatetruecolor($new_width, $new_height);
$source      =   imagecreatefromjpeg("$base_image");
imagecopyresized($thumb, $source, 0,0,0,0, $new_width, $new_height, $width, $height);
//header('Content-type: image/jpeg');
imagejpeg($thumb);
imagedestroy($thumb);
?>

Really not alot faster than loading the image using the img tag and resizing it but we'll see when I get 100's of files in there. Very Happy
Related topics
America's Army
No backups anymore?
pls suggest software to generate thumbnails etc...
Get your logo/banner/any thing else made... 2-10 frih $
Thumbnails on the fly
ImageMagick - How to add text?
Problem creating new table and inserting
Setting up E-mail Problems
Problem with galary script
Audio CD burning.
I could not add my domain name to my account
My host is acting weird
Forum Philosophy
A vision of the ideal economy...
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.