Re: More efficient thumbnail script

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 




On Jan 16, 2007, at 4:15 PM, Paul Novitski wrote:

At 1/16/2007 12:54 PM, Jason Pruim wrote:
First off, thanks to everyone who helped me get started with a
thumbnail gallery that would display info you could just copy/paste
into a weblog (Or any webpage) and have the picture display.

I am moving along with a few additions and seem to be running into a
problem. The script I have works just fine, it's just slow when you
put some large files in it, the page takes awhile to load weither I'm
calling it through the php file it's self or through a include in an
html file.
...
The php script I'm using can be seen here: http://www.raoset.com/ tests/picture/images/wheeler.php

the html file I want to include it in is: http://www.raoset.com/ tests/ pictures/index.shtml


Jason,

I'm not able to see your PHP script because when I navigate to the script it is interpreted, not downloaded as text. Please copy the script into a file ending in .txt if you'd like people to be able to read it.

Is your thumbnail script slow because you're creating images on the fly every time? If so, an obvious fix would be to cache thumbnails on the server so you only have to create them once. The logic could look something like:

        if (thumnbail doesn't exist)
        {
                // create thumbnail & save it to the server
        }

// use existing file

Then you might consider putting the thumbnail-cacheing logic into the script that lets people upload their images in the first place, so there won't be so much processing the first time the thumbnail gallery is loaded.
Sorry... Not used to working with PHP scripts... I forget you can't just "view source" them :) here is the wheeler.php script:
<?

/* ************************************
** James Wheeler
** Kender Internet Kompany
** http://kender.org
**
** Name as index.php
** - Display all images in a directory
** - Able to skip files at will
** - remove <img src= and use for
**   all files in directory
**   (skipping desired files)
**
** Code free to use, please give credit
** where credit is due!
************************************ */


echo '<center>
Click on a thumbnail to view image<br />
<table>
    <tr>
';

$main = ".";
$dir = opendir($main); // unbutton it
$i = 1;         												// for column count


while($filename = readdir($dir))
{
    {
if (filetype($filename) == "file" && $filename !="index.php" && $filename !=".DS_Store" && $filename !="uploadac.php" && $filename !="wheeler.php" && $file !="wheeler.css" && $file ! ="wheeletest.php" && $file !="wheeler.shtml" && $file !="index.shtml" && $file !="picture.css" && $file !="picture.txt") // dont show index.php (this file) - skip any file you dont want viewed // format as ( && $filename != "filename.ext" ) inside the () behind "index.php"
        {
if ($i <= '1') // column count (designed for 5 columns wide - change the 5 for however many wanted)
            {
                $i = $i + '1';
               echo '        <td align="left" width="115" height="100">
<a href="images/'.$filename.'"><img src="images/'.$filename.'" height="60" border="0" /></a><br />';
							
$imgHTML = '<a href="http://www.raoset.com/tests/picture/ images/'.$filename.'"><img src="http://www.raoset.com/tests/picture/ images/'.$filename.'" height="200px"/></A>';
								$imgHTML = htmlentities($imgHTML, ENT_QUOTES);
								echo $imgHTML;

	               echo '           </td>
'; // display it
            } else {
$i = '1'; // reset column count and change rows
                echo '    </tr>
    <tr>
';
$i = $i + '1'; // add 1 to counter to get to next row echo ' <td align="left" width="115" height="100"> <a href="images/'.$filename.'"><img src="images/'.$filename.'" height="60" border="0" /></a><br /> '; $imgHTML = '<a href="http:// www.raoset.com/tests/picture/images/'.$filename.'"><img src="http:// www.raoset.com/tests/picture/images/'.$filename.'" height="200px"/></ A>';
								$imgHTML = htmlentities($imgHTML, ENT_QUOTES);
								echo $imgHTML;
                     echo '       </td>
'; // display it
            }
        }
    }
}

closedir($dir); // button it up

echo '
    </tr>
</table>
</center>
';

// echo ' <td align="left" width="115" height="100"> // <a href="'.$filename.'"><img src="'. $filename.'" height="60" border="0" /></a><br /> // <font size="1" face="tahoma">'. $filename.'<br />'.filesize($filename).' bytes. <BR /> link info: &le;img //src=&quot;http://www.raoset.com/media/images/texas/images/'. $filename.'&quot; height="50%" &ge;</font>
//
exit;
?>

and here is my uploadac.php script:

<?php
//set where you want to store files
//in this example we keep file in folder upload
//$HTTP_POST_FILES['ufile']['name']; = upload file name
//for example upload file name cartoon.gif . $path will be upload/ cartoon.gif
$path1= "images/".$HTTP_POST_FILES['ufile']['name'][0];
$path2= "images/".$HTTP_POST_FILES['ufile']['name'][1];
$path3= "images/".$HTTP_POST_FILES['ufile']['name'][2];
$path4= "images/".$HTTP_POST_FILES['ufile']['name'][3];
$path5= "images/".$HTTP_POST_FILES['ufile']['name'][4];
$path6= "images/".$HTTP_POST_FILES['ufile']['name'][5];
$path7= "images/".$HTTP_POST_FILES['ufile']['name'][6];
$path8= "images/".$HTTP_POST_FILES['ufile']['name'][7];
$path9= "images/".$HTTP_POST_FILES['ufile']['name'][8];
$path10= "images/".$HTTP_POST_FILES['ufile']['name'][9];

//copy file to where you want to store file
copy($HTTP_POST_FILES['ufile']['tmp_name'][0], $path1);
copy($HTTP_POST_FILES['ufile']['tmp_name'][1], $path2);
copy($HTTP_POST_FILES['ufile']['tmp_name'][2], $path3);
copy($HTTP_POST_FILES['ufile']['tmp_name'][3], $path4);
copy($HTTP_POST_FILES['ufile']['tmp_name'][4], $path5);
copy($HTTP_POST_FILES['ufile']['tmp_name'][5], $path6);
copy($HTTP_POST_FILES['ufile']['tmp_name'][6], $path7);
copy($HTTP_POST_FILES['ufile']['tmp_name'][7], $path8);
copy($HTTP_POST_FILES['ufile']['tmp_name'][8], $path9);
copy($HTTP_POST_FILES['ufile']['tmp_name'][9], $path10);
header('Location: HTTP://www.raoset.com/tests/picture/index.shtml');
exit;

Thanks for looking! :)



--

Jason Pruim
japruim@xxxxxxxxxx
Production & Technology Manager
MQC Specialist (2005 certified)
3251 132nd Ave
Holland MI 49424
616.399.2355
www.raoset.com


“Give me your tired, your poor,
Your huddled masses yearning to breathe free,
The wretched refuse of your teeming shore.
Send these, the homeless tempest-tost to me,
I lift my lamp beside the golden door!”

From “The New Colossus,” by Emma Lazarus



Attachment: smime.p7s
Description: S/MIME cryptographic signature


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux