|
Posted by Confused but working on it on 09/14/07 22:36
On 2007-09-13 07:37:21 -0700, "Steve" <no.one@example.com> said:
>
> "Confused but working on it" <PostInGroups@wherever.com> wrote in
> message news:2007091209500416807-PostInGroups@wherevercom...
>> Just wanted to say thanks for the posts helping me make ths work. Added
>> a few comments and after the readdir used a pattern match to test for
>> .jpg, and seems to work fine on my test setup. Maybe I should test for
>> gif, tiff, and png... Anyway, here's the code:
>> <?php
>> //Open images directory
>> $dir = opendir("images");
>> //read files in the dir
>> while (($file = readdir($dir)) !== false)
>> //test to make sure jpg
>> if (eregi("\.jpg",$file))
>
> one suggestion,
>
> why are you using ereg? beside the fact that it is vastly more resource
> intensive than preg and slower, neither is needed because substr is
> faster than both.
>
> while ...
> $extension = strtolower(substr($file, -4));
> if ($extension != '.jpg'){ continue; }
> whatever you want to do with the jpg from here
> end
>
> you could also use fnmatch to pattern match for file names. you could
> even use glob()...
>
> $directory = 'images';
> $extension = '*.jpg';
> chdir($directory);
> foreach (glob($extension) as $image)
> {
> echo '<img src="' . $directory . '/' . $image . '" class="pad1em">';
> }
>
> i personally prefer glob() for such things since it requires less code
> to get what you want.
>
> anyway...there's always more than one way to skin a cat. ;^)
Here's how I changed the line:
echo "<a href='images/$file'><img src='thumbs/$file'
class=\"pad1em\"></a>";
My originals were 1600x1200 so I did a bew export to thumbs at 100x75
and another to images at 400x300. Freakin fantastic! Had to refresh the
page as the old thumb was showing but very cool. Will play with size I
shoot at and then corresponding thumbs and bigger versions. Like 1024
wide makes nice thumbs at 128, click to see a 512 or 640 bersion.
Before I start hacking your code in from above, any reason the
following wont work?
> if ($extension != '.jpg' or != 'gif' or != '.tif' ){ continue; }
Or use the whole expression?
Thanks again!
ron
Navigation:
[Reply to this message]
|