Hello,
Im trying to create a image gallery that takes images from a directory by creating thumbnails on the fly.
my problem is having to display it in a bacth order using html when i cant cause i have to header()
im looking into the output buffering but it doesnt seem to explain much of its working in the docs.
i wanna be able to display the dyanimcally created thumbnails in table rows...can this be done? how?
Kendall
outputing dynamically created thumnail images to browsers
Moderator: General Moderators
What needs to go in your header() that is so important?
What are you using to generate the thumbs? Are you using the GD libraries? (doing them on the fly is slow - as each new user causes the thumbnails to be resampled again. Better to generate them once with a script, then use them directly in the gallery.)
Echoing an html table is simple, once you've read in the files:
Do all your header stuff, then type
maketable('thumbs','pics',8);
and you'll get a table.
(The above code should work - its been copied and pasted in pieces, but should still work)
What are you using to generate the thumbs? Are you using the GD libraries? (doing them on the fly is slow - as each new user causes the thumbnails to be resampled again. Better to generate them once with a script, then use them directly in the gallery.)
Echoing an html table is simple, once you've read in the files:
Code: Select all
<?php
function maketable ($thumb_dir,$img_dir,$width) {
// ***************************************
// *** Read in directory, create array ***
// *** of all jpgs and sort. ***
// ***************************************
if ($dir = @opendir($thumb_dir)) {
while (($file = readdir($dir)) !== false) {
if ($file !== "." && $file !== ".." && strrchr($file,'.')=='.jpg') {
$img_list[] = $file;
}
}
closedir($dir);
}
sort($img_list);
// *************************
// *** Start HTML output ***
// *************************
echo "<TABLE>";
for ($i=0; $i<count($img_list); $i++) {
//Paths to images
$thumb_url = $thumb_dir . $img_list[$i];
$img_name = str_replace("th","",$img_list[$i]);
$img_url = $img_dir . $img_name;
echo
"<td VALIGN=middle ALIGN=center><a href="$img_url">
<img src="$thumb_url" width="$size[0]"
height="$size[1]" border=0></a></td>\n";
//Wrap table at right no of columns
if (($i+1) % $width == 0 ) echo "</tr><tr>\n";
}
echo "</tr></table>\n";
}
?>maketable('thumbs','pics',8);
and you'll get a table.
(The above code should work - its been copied and pasted in pieces, but should still work)
- kendall
- Forum Regular
- Posts: 852
- Joined: Tue Jul 30, 2002 10:21 am
- Location: Trinidad, West Indies
- Contact:
outputing dynamically created thumnail images to browsers
Rfaiy,
I was using the header('Content-type : image/jpeg') to output the dyanimcally created thumbnails to the browser...the process would have created a web photo gallery. I was looking at server space hence the reason thumnails were created on the fly.
The person was allowed to create his/ her web photo gallery. but i guess i will have to create the thumnails on image uploads since they were goin to be slow (thought i was faster/ easier)...then i guess i could always readdir() and do a <img src=file> and create the html tables as necessary
ok
i think i have a better angle now thanks
Kendall
I was using the header('Content-type : image/jpeg') to output the dyanimcally created thumbnails to the browser...the process would have created a web photo gallery. I was looking at server space hence the reason thumnails were created on the fly.
The person was allowed to create his/ her web photo gallery. but i guess i will have to create the thumnails on image uploads since they were goin to be slow (thought i was faster/ easier)...then i guess i could always readdir() and do a <img src=file> and create the html tables as necessary
ok
i think i have a better angle now thanks
Kendall