PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > comp.lang.php > My readdir and display images snippet - Thanks
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
My readdir and display images snippet - Thanks

Réponse
 
LinkBack Outils de la discussion
Vieux 12/09/2007, 18h50   #1
Confused but working on it
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut My readdir and display images snippet - Thanks

Just wanted to say thanks for the posts ing 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))
{
echo "<img src='images/$file' class=\"pad1em\">";
}
closedir($dir);
?>

For my next trick I'm going to change the above to read a thumbs dir,
and make a link to a larger picture of the same name in images.
Shouldn't be too hard bt my last programming class was almost 20 years
ago. Hats off to everyone that does this for a living.

Thanks again!

  Réponse avec citation
Vieux 13/09/2007, 16h37   #2
Steve
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: My readdir and display images snippet - Thanks


"Confused but working on it" <PostInGroups@wherever.com> wrote in message
news:2007091209500416807-PostInGroups@wherevercom...
> Just wanted to say thanks for the posts ing 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. ;^)


  Réponse avec citation
Vieux 13/09/2007, 17h10   #3
Captain Paralytic
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: My readdir and display images snippet - Thanks

On 12 Sep, 17:50, Confused but working on it
<PostInGro...@wherever.com> wrote:
> Just wanted to say thanks for the posts ing 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))
> {
> echo "<img src='images/$file' class=\"pad1em\">";
> }
> closedir($dir);
> ?>
>
> For my next trick I'm going to change the above to read a thumbs dir,
> and make a link to a larger picture of the same name in images.
> Shouldn't be too hard bt my last programming class was almost 20 years
> ago. Hats off to everyone that does this for a living.
>
> Thanks again!


I think that your ereg might find files such as fred.jpgs.php

  Réponse avec citation
Vieux 13/09/2007, 18h07   #4
Steve
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: My readdir and display images snippet - Thanks


"Confused but working on it" <PostInGroups@wherever.com> wrote in message
news:2007091209500416807-PostInGroups@wherevercom...
> Just wanted to say thanks for the posts ing 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:


ok, so i've got time on my hands...after re-reading posts today, i'm on this
one again. here's something that will allow you to list any file you want
either filtering by extension or just getting everything. i've been using
the function below since glob became availabe in php. beneath it, i wrapped
up some pseudo-testing code so you could see how the function can be called
and what each param will generate for you.

have fun. ;^)

<?
function listFiles($path, $extension = array(), $combine = false)
{
if (!chdir($path)){ return array(); }
if (!$extension){ $extension = array('*'); }
if (!is_array($extension)){ $extension = array($extension); }
$extensions = '*.{' . implode(',', $extension) . '}';
$files = glob($extensions, GLOB_BRACE);
if (!$files){ return array(); }
$list = array();
foreach ($files as $file)
{
$list[] = ($combine ? $path : '') . $file;
}
return $list;
}

// sampling output
function beautify($html)
{
$html = str_replace(' :: Array', '', $html);
return $html;
}
ob_start('beautify');
// end sample

// test the function
$path = 'c:/inetpub/wwwroot/images';
$extensions = array('jpg', 'gif', 'tif?');

echo '<pre>directory listing for "' . $path . '"</pre>';

$images = listFiles($path);
echo '<pre>no filter, no directory :: ' . print_r($images, true) . '</pre>';

$images = listFiles($path, null, true);
echo '<pre>no filter :: ' . print_r($images, true) . '</pre>';

$images = listFiles($path, 'jpg', true);
echo '<pre>single filter :: ' . print_r($images, true) . '</pre>';

$images = listFiles($path, $extensions, true);
echo '<pre>multiple filter :: ' . print_r($images, true) . '</pre>';
?>


  Réponse avec citation
Vieux 14/09/2007, 23h34   #5
Confused but working on it
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: My readdir and display images snippet - Thanks

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 ing 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. ;^)


Hey Steve,

I'm using eregi because I found a line on a site or in the manual that
didn't get .jpg so I fixed it to get the jpgs. Not a programmer, and
barely even a hobbyist so I do what I can to kludge some stuff
together. Maybe I can read preg, substr and glob and use one of them
but was pretty happy with the cat being skinned at all.
Basically I'm just writing a paragraph about and event and putting
160px images on the page with a bit of padding. Today I was going to
make this thing read thumbs and link to images... Might have to take a
nap.

Thanks for the

  Réponse avec citation
Vieux 14/09/2007, 23h42   #6
Confused but working on it
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: My readdir and display images snippet - Thanks

On 2007-09-13 08:10:48 -0700, Captain Paralytic <paul_lautman@yahoo.com> said:

> On 12 Sep, 17:50, Confused but working on it
> <PostInGro...@wherever.com> wrote:
>> Just wanted to say thanks for the posts ing 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))
>> {
>> echo "<img src='images/$file' class=\"pad1em\">";
>> }
>> closedir($dir);
>> ?>
>>
>> For my next trick I'm going to change the above to read a thumbs dir,
>> and make a link to a larger picture of the same name in images.
>> Shouldn't be too hard bt my last programming class was almost 20 years
>> ago. Hats off to everyone that does this for a living.
>>
>> Thanks again!

>
> I think that your ereg might find files such as fred.jpgs.php


Yo Captain! (ex-nick of mine)

So that will never be found because fred and I, well, his wife will
tell you the whole story...

Just like a million other peeps I take pictures. I load em up in my mac
in iPhoto, make an album with the corresponding name and don't include
shats that were crappy. Export to a dir called images, filezilla to my
site. Use my little code to display on a page. I tried iWeb to make
pages, gallery databases done in php, and holy cow way to complicated.
Just easier to manage everything in directories by some kind of topic.

So is there a way for your exampe to happen?

Thanks for your input,
Ron

  Réponse avec citation
Vieux 14/09/2007, 23h50   #7
Confused but working on it
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: My readdir and display images snippet - Thanks

On 2007-09-13 09:07:17 -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 ing 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:

>
> ok, so i've got time on my hands...after re-reading posts today, i'm on
> this one again. here's something that will allow you to list any file
> you want either filtering by extension or just getting everything. i've
> been using the function below since glob became availabe in php.
> beneath it, i wrapped up some pseudo-testing code so you could see how
> the function can be called and what each param will generate for you.
>
> have fun. ;^)
>
> <?
> function listFiles($path, $extension = array(), $combine = false)
> {
> if (!chdir($path)){ return array(); }
> if (!$extension){ $extension = array('*'); }
> if (!is_array($extension)){ $extension = array($extension); }
> $extensions = '*.{' . implode(',', $extension) . '}';
> $files = glob($extensions, GLOB_BRACE);
> if (!$files){ return array(); }
> $list = array();
> foreach ($files as $file)
> {
> $list[] = ($combine ? $path : '') . $file;
> }
> return $list;
> }
>
> // sampling output
> function beautify($html)
> {
> $html = str_replace(' :: Array', '', $html);
> return $html;
> }
> ob_start('beautify');
> // end sample
>
> // test the function
> $path = 'c:/inetpub/wwwroot/images';
> $extensions = array('jpg', 'gif', 'tif?');
>
> echo '<pre>directory listing for "' . $path . '"</pre>';
>
> $images = listFiles($path);
> echo '<pre>no filter, no directory :: ' . print_r($images, true) . '</pre>';
>
> $images = listFiles($path, null, true);
> echo '<pre>no filter :: ' . print_r($images, true) . '</pre>';
>
> $images = listFiles($path, 'jpg', true);
> echo '<pre>single filter :: ' . print_r($images, true) . '</pre>';
>
> $images = listFiles($path, $extensions, true);
> echo '<pre>multiple filter :: ' . print_r($images, true) . '</pre>';
> ?>


Steve,

Wow, way too much time on your hands.

My first goal was to get my pics to display, then get rid of the . and
..., now I will fix the code to the example you gave before if you say
it's faster. Then,(light drumroll...), I want to read everything in
thumbs and create my output so I get the thumbto link to a larger pic
in images. Some sort of anchor tag thing. THAT would be cool to me.
Then I can rewrite about 20 pages, export 20 albums as thumbs and 20
albums as images...

I'm going to make my anchor tag...

thx..ron

  Réponse avec citation
Vieux 15/09/2007, 00h36   #8
Confused but working on it
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: My readdir and display images snippet - Thanks

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 ing 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

  Réponse avec citation
Vieux 15/09/2007, 04h30   #9
Rik Wasmus
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: My readdir and display images snippet - Thanks

On Fri, 14 Sep 2007 23:42:46 +0200, Confused but working on it
<PostInGroups@wherever.com> wrote:

> On 2007-09-13 08:10:48 -0700, Captain Paralytic <paul_lautman@yahoo.com>
> said:
>
>> On 12 Sep, 17:50, Confused but working on it
>> <PostInGro...@wherever.com> wrote:
>>> Just wanted to say thanks for the posts ing 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))
>>> {
>>> echo "<img src='images/$file' class=\"pad1em\">";


Hmm, are you sure about the class name? I'd say that on a new layout with
the same HTML 'pad1em' could end up making very little sense. A golden
rule of css is that a classname should reflect what something is, not how
it is _displayed. A more suitable name could be something like
'imagepreview' or the like.

>>> }
>>> closedir($dir);
>>> ?>
>>> For my next trick I'm going to change the above to read a thumbs dir,
>>> and make a link to a larger picture of the same name in images.
>>> Shouldn't be too hard bt my last programming class was almost 20 years
>>> ago. Hats off to everyone that does this for a living.
>>> Thanks again!

>> I think that your ereg might find files such as fred.jpgs.php

>
> Yo Captain! (ex-nick of mine)
>
> So that will never be found because fred and I, well, his wife will tell
> you the whole story...
>
> Just like a million other peeps I take pictures. I load em up in my mac
> in iPhoto, make an album with the corresponding name and don't include
> shats that were crappy. Export to a dir called images, filezilla to my
> site. Use my little code to display on a page. I tried iWeb to make
> pages, gallery databases done in php, and holy cow way to complicated.
> Just easier to manage everything in directories by some kind of topic.
>
> So is there a way for your exampe to happen?


Oh yeah.
(Just make sure the file is a proper image directly after an upload.
Examining extention or mime-type is no good. I'm quite happy to us
getimagesize() for this purpose, as it would return false if it couldn't
interpret a file as an image.)

And to display only files _ending_ in jp(e)g, I'd use
preg_match('/\.jpe?g$/i',$string);
--
Rik Wasmus
  Réponse avec citation
Vieux 16/09/2007, 04h47   #10
Steve
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: My readdir and display images snippet - Thanks


"Confused but working on it" <PostInGroups@wherever.com> wrote in message
news:2007091414504450073-PostInGroups@wherevercom...
> On 2007-09-13 09:07:17 -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 ing 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:

>>
>> ok, so i've got time on my hands...after re-reading posts today, i'm on
>> this one again. here's something that will allow you to list any file you
>> want either filtering by extension or just getting everything. i've been
>> using the function below since glob became availabe in php. beneath it, i
>> wrapped up some pseudo-testing code so you could see how the function can
>> be called and what each param will generate for you.
>>
>> have fun. ;^)
>>
>> <?
>> function listFiles($path, $extension = array(), $combine = false)
>> {
>> if (!chdir($path)){ return array(); }
>> if (!$extension){ $extension = array('*'); }
>> if (!is_array($extension)){ $extension = array($extension); }
>> $extensions = '*.{' . implode(',', $extension) . '}';
>> $files = glob($extensions, GLOB_BRACE);
>> if (!$files){ return array(); }
>> $list = array();
>> foreach ($files as $file)
>> {
>> $list[] = ($combine ? $path : '') . $file;
>> }
>> return $list;
>> }
>>
>> // sampling output
>> function beautify($html)
>> {
>> $html = str_replace(' :: Array', '', $html);
>> return $html;
>> }
>> ob_start('beautify');
>> // end sample
>>
>> // test the function
>> $path = 'c:/inetpub/wwwroot/images';
>> $extensions = array('jpg', 'gif', 'tif?');
>>
>> echo '<pre>directory listing for "' . $path . '"</pre>';
>>
>> $images = listFiles($path);
>> echo '<pre>no filter, no directory :: ' . print_r($images, true) .
>> '</pre>';
>>
>> $images = listFiles($path, null, true);
>> echo '<pre>no filter :: ' . print_r($images, true) . '</pre>';
>>
>> $images = listFiles($path, 'jpg', true);
>> echo '<pre>single filter :: ' . print_r($images, true) . '</pre>';
>>
>> $images = listFiles($path, $extensions, true);
>> echo '<pre>multiple filter :: ' . print_r($images, true) . '</pre>';
>> ?>

>
> Steve,
>
> Wow, way too much time on your hands.


i think when i originally wrote that, it took all of about 5 minutues. ;^)

> My first goal was to get my pics to display, then get rid of the . and ..,
> now I will fix the code to the example you gave before if you say it's
> faster. Then,(light drumroll...), I want to read everything in thumbs and
> create my output so I get the thumbto link to a larger pic in images. Some
> sort of anchor tag thing. THAT would be cool to me. Then I can rewrite
> about 20 pages, export 20 albums as thumbs and 20 albums as images...


you realize you don't have to have a thumb of each pic in order to generate
a thumb, right?

if you'd like, i can post a class that does this based on the actual image,
and then show how to use it in your main script.


  Réponse avec citation
Vieux 16/09/2007, 07h45   #11
Confused but working on it
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: My readdir and display images snippet - Thanks

On 2007-09-14 19:30:34 -0700, "Rik Wasmus" <luiheidsgoeroe@hotmail.com> said:
>>>>
>>>> echo "<img src='images/$file' class=\"pad1em\">";

>
> Hmm, are you sure about the class name? I'd say that on a new layout wit h
> the same HTML 'pad1em' could end up making very little sense. A golden
> rule of css is that a classname should reflect what something is, not ho w
> it is _displayed. A more suitable name could be something like
> 'imagepreview' or the like.
>
>>

>
> Oh yeah.
> (Just make sure the file is a proper image directly after an upload.
> Examining extention or mime-type is no good. I'm quite happy to us
> getimagesize() for this purpose, as it would return false if it couldn't
> interpret a file as an image.)
>
> And to display only files _ending_ in jp(e)g, I'd use
> preg_match('/\.jpe?g$/i',$string);
> --
> Rik Wasmus


Rik,

Thanks for responding. In this case the class name is what it is.
..pad1em{padding: 1em;}

Was just messing with some spacing and will rename if I add some pretty
decorations. Any suggestions for this class?

thx..ron

  Réponse avec citation
Vieux 16/09/2007, 08h04   #12
Confused but working on it
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: My readdir and display images snippet - Thanks

>>
>> Steve,
>>
>> Wow, way too much time on your hands.

>
> i think when i originally wrote that, it took all of about 5 minutues. ;^)
>
>> My first goal was to get my pics to display, then get rid of the . and
>> .., now I will fix the code to the example you gave before if you say
>> it's faster. Then,(light drumroll...), I want to read everything in
>> thumbs and create my output so I get the thumbto link to a larger pic
>> in images. Some sort of anchor tag thing. THAT would be cool to me.
>> Then I can rewrite about 20 pages, export 20 albums as thumbs and 20
>> albums as images...

>
> you realize you don't have to have a thumb of each pic in order to
> generate a thumb, right?
>
> if you'd like, i can post a class that does this based on the actual
> image, and then show how to use it in your main script.


Well hell yeah, post away!

I was trying to do it myself as I see a lot of posts asking for free work.

At this point storage isn't an issue and it takes 20 seconds to
generate the thumbs and the resized images from iPhoto. As opposed to
if I had a 1600x1200 pic and uploaded I think that takes more storage
than a 800px pic and a 100px thumb. Let me see if I can write a script
to calculate the storage difference...

So when I take pics I make a dir and make images and thumbs dir inside
of that. The I have a very simple php page with includes for header and
footer. Change the title, add my paragraph or two and then my thumbs
output. I tried to use iWeb for plain export of html pages but ends up
being more work because every file extension needs to be changed to
php, footer and header added, css line to be added. UGH.

So in 67 lines of code or less, read my images, display as thumbs
linking back to the originals, sorted by filename...



Thanks,
Ron

  Réponse avec citation
Vieux 17/09/2007, 01h56   #13
Steve
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: My readdir and display images snippet - Thanks


"Confused but working on it" <PostInGroups@wherever.com> wrote in message
news:2007091523044150073-PostInGroups@wherevercom...
>>>
>>> Steve,
>>>
>>> Wow, way too much time on your hands.

>>
>> i think when i originally wrote that, it took all of about 5 minutues.
>> ;^)
>>
>>> My first goal was to get my pics to display, then get rid of the . and
>>> .., now I will fix the code to the example you gave before if you say
>>> it's faster. Then,(light drumroll...), I want to read everything in
>>> thumbs and create my output so I get the thumbto link to a larger pic in
>>> images. Some sort of anchor tag thing. THAT would be cool to me. Then I
>>> can rewrite about 20 pages, export 20 albums as thumbs and 20 albums as
>>> images...

>>
>> you realize you don't have to have a thumb of each pic in order to
>> generate a thumb, right?
>>
>> if you'd like, i can post a class that does this based on the actual
>> image, and then show how to use it in your main script.

>
> Well hell yeah, post away!
>
> I was trying to do it myself as I see a lot of posts asking for free work.
>
>
> At this point storage isn't an issue and it takes 20 seconds to generate
> the thumbs and the resized images from iPhoto. As opposed to if I had a
> 1600x1200 pic and uploaded I think that takes more storage than a 800px
> pic and a 100px thumb. Let me see if I can write a script to calculate the
> storage difference...
>
> So when I take pics I make a dir and make images and thumbs dir inside of
> that. The I have a very simple php page with includes for header and
> footer. Change the title, add my paragraph or two and then my thumbs
> output. I tried to use iWeb for plain export of html pages but ends up
> being more work because every file extension needs to be changed to php,
> footer and header added, css line to be added. UGH.
>
> So in 67 lines of code or less, read my images, display as thumbs linking
> back to the originals, sorted by filename...


ok...call this script get.thumb.nail.php (or whatever you'd like).
site.cfg.php is a configuration script that objectifies different things for
my site...in this case, where included directories are. hard-code as you see
fit. below this main script you'll find the functions used and supplied by
functions.inc.php. finally, below that, you'll see an example use of
everything together. if you have questions or need , just post back.

cheers...

========

get.thumb.nail.php

<?
require_once 'site.cfg.php';
require_once $site->includeDirectory . 'functions.inc.php';
$fileName = $_REQUEST['fileName'] ? $_REQUEST['fileName'] :
$_REQUEST['altImage'];
$maxSize = $_REQUEST['maxSize'] ? $_REQUEST['maxSize'] : 200;
$filePath = $site->imagesDirectory;
$fileData = @file_get_contents($filePath . $fileName);
$originalImage = @imagecreatefromstring($fileData);
@list($imageWidth, $imageHeight, $imageType, $imageAttributes) =
@getimagesize($filePath . $fileName);
$newImageHeight = $imageWidth < $maxSize ? $imageHeight : ($imageHeight /
$imageWidth) * $maxSize;
$newImageWidth = $imageWidth < $maxSize ? $imageWidth : $maxSize;
$thumbNail = @imagecreatetruecolor($newImageWidth, $newImageHeight);
@imagecopyresampled(
$thumbNail,
$originalImage,
0,
0,
0,
0,
$newImageWidth,
$newImageHeight,
@imagesx($originalImage),
@imagesy($originalImage)
);
@imagejpeg($thumbNail);
@imagedestroy($thumbNail);
@imagedestroy($originalImage);
?>

======

get.file.php

<?
require_once 'site.cfg.php';
$fileData = '';
$fileName = $_REQUEST['fileName'];
$filePath = $site->uploadBaseDirectory;
if ($fileName != ''){ $fileData = @file_get_contents($filePath .
$fileName); }
header('pragma: public' );
header('expires: 0' );
header('cache-control: private', false );
header('cache-control: must-revalidate, post-check=0, pre-check=0' );
header('content-disposition: attachment; filename="' . $fileName . '"' );
header('content-size: ' . count($fileData) );
header('content-transfer-encoding: binary' );
header('content-type: application/octet-stream' );
echo $fileData;
?>

=======

test.php

<?
$sql = "
SELECT Id
,
Description
,
FileName
,
FileSize
,
FileType
,
DATE_FORMAT(Stamp, '%m/%d/%Y %H:%i:%s') Stamp
FROM upLoads
ORDER BY FileName
";
$records = db::execute($sql);
foreach ($records as $row => $record)
{
$queryString = "?fileName=" . $record['FILENAME'] . "&maxSize=200";
?>
<a
href="<?= $site->uri ?>get.file.php<?= $queryString ?>"
style="font-size:12pt;"
>

<img
src="<?= $site->uri ?>get.thumb.nail.php<?= $queryString ?>"
alt="<?= $record['DESCRIPTION'] ?>"
title="Click To Open: <?= $record['DESCRIPTION'] ?>"
/>
</a>

<?
}
?>


  Réponse avec citation
Vieux 19/09/2007, 17h55   #14
Confused but working on it
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: My readdir and display images snippet - Thanks

On 2007-09-16 16:56:01 -0700, "Steve" <no.one@example.com> said:
<snip>
?>
> <a
> href="<?= $site->uri ?>get.file.php<?= $queryString ?>"
> style="font-size:12pt;"
> >

> <img
> src="<?= $site->uri ?>get.thumb.nail.php<?= $queryString ?>"
> alt="<?= $record['DESCRIPTION'] ?>"
> title="Click To Open: <?= $record['DESCRIPTION'] ?>"
> />
> </a>
>
> <?
> }
> ?>


Steve,

Thanks for posting this. I did a cut and paste and will rty to
implement soon. Have had to work the past few days.

Thanks,
Ron

  Réponse avec citation
Vieux 19/09/2007, 18h10   #15
Steve
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: My readdir and display images snippet - Thanks


"Confused but working on it" <PostInGroups@wherever.com> wrote in message
news:2007091908554916807-PostInGroups@wherevercom...
> On 2007-09-16 16:56:01 -0700, "Steve" <no.one@example.com> said:
> <snip>
> ?>
>> <a
>> href="<?= $site->uri ?>get.file.php<?= $queryString ?>"
>> style="font-size:12pt;"
>> >

>> <img
>> src="<?= $site->uri ?>get.thumb.nail.php<?= $queryString ?>"
>> alt="<?= $record['DESCRIPTION'] ?>"
>> title="Click To Open: <?= $record['DESCRIPTION'] ?>"
>> />
>> </a>
>>
>> <?
>> }
>> ?>

>
> Steve,
>
> Thanks for posting this. I did a cut and paste and will rty to implement
> soon. Have had to work the past few days.
>
> Thanks,
> Ron


no problem. let me know how it goes.


  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 16h39.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,60955 seconds with 23 queries