Generating images on the front page.

D

Dave Kelly

I need to do the equivalent of this in HTML.
===========#============
#!/bin/sh


for filename in *.jpg *.gif *.png; ##list all images in directory
do
<img src=images/"${filename}" width="190">
done
============#============

My O'Reilly book has only 1 paragraph on generating random images and
not code examples. I have googled and come up with some php and java
code. I wanted to keep away from that if I could because in the future
when someone else take over admin duties on the club website, they
probably will not know those languages.

This directory is continually having images added. I want something
simple that I can drop into the from page of the website.

Ideally, generate a new image every time the front page is accessed.
EV1 is the host server if that makes any difference.


TIA
Dave
 
J

Jonathan N. Little

Dave said:
I need to do the equivalent of this in HTML.
===========#============
#!/bin/sh


for filename in *.jpg *.gif *.png; ##list all images in directory
do
<img src=images/"${filename}" width="190">
done
============#============

My O'Reilly book has only 1 paragraph on generating random images and
not code examples. I have googled and come up with some php and java
code. I wanted to keep away from that if I could because in the future
when someone else take over admin duties on the club website, they
probably will not know those languages.

This directory is continually having images added. I want something
simple that I can drop into the from page of the website.

Ideally, generate a new image every time the front page is accessed.
EV1 is the host server if that makes any difference.

Sorry, no can do. HTML is only markup not scripting, to do what you wish
*requires* a script either server-side (best) PHP, Perl, Python, ASP,
ColdFusion, ... or client-side (not-so-good) JavaScript.
 
T

Toby Inkster

Jonathan said:
Sorry, no can do. HTML is only markup not scripting, to do what you wish
*requires* a script either server-side (best) PHP, Perl, Python, ASP,
ColdFusion, ... or client-side (not-so-good) JavaScript.

Client-side Javascript won't do -- it has no way of reading the contents
of a directory on the server.
 
A

Andy Dingley

Toby said:
Client-side Javascript won't do -- it has no way of reading the contents
of a directory on the server.

Well it _might_ do. Stick the images in an images/ subdirectory and
let the web server serve the default directory listing, then parse it
client side. Still an ugly way to do it though.

Find out what your hosting supports easily (probably PHP) and write a
server-side script for it.This is very easy, low maintenance, and you
can probably download a workable example.
 
J

Jonathan N. Little

Toby said:
Client-side Javascript won't do -- it has no way of reading the contents
of a directory on the server.
Yes, you would have to manually make the list, I focused on the 'select
image at random' part and overlooked the 'list all images in directory'
part.
 
D

Dave Kelly

Jonathan said:
Sorry, no can do. HTML is only markup not scripting, to do what you wish
*requires* a script either server-side (best) PHP, Perl, Python, ASP,
ColdFusion, ... or client-side (not-so-good) JavaScript.
OK, Thanks. Never know 'til you ask.
D
 
D

Dave Kelly

Jonathan said:
Yes, you would have to manually make the list, I focused on the 'select
image at random' part and overlooked the 'list all images in directory'
part.
I have found a couple of PHP apps that do the job. Keeping the list of
images in the directory current was the problem. All I found required
you to make a stable list. I have not figured how to update the list on
the server.

I know that EV1 runs PHP because I have the SMF code running. I just
need to check and see what hooks to scheduling they have.

Thanks
D
 
R

Rik

Dave said:
I have found a couple of PHP apps that do the job. Keeping the list of
images in the directory current was the problem. All I found required
you to make a stable list. I have not figured how to update the list
on the server.

I know that EV1 runs PHP because I have the SMF code running. I just
need to check and see what hooks to scheduling they have.

HTML: <img src="/path/to/dir/random.php" />

random.php:
<?php

$dh = opendir(dirname(__FILE__));

$images = array();
$img_extensions = array('jpeg','jpg','png','gif');

while (($file = readdir($dh))!==false){
if(is_file(dirname(__FILE__).'/'.$file)){
preg_match('/([^.]*)$/si',$file,$matches);
if(in_array(strtolower($matches[1]),$img_extensions)){
$images[] = $file;
}
}
}
closedir($dh);
$chosen ='./'.$images[rand(0,count($images)-1)];
$size = getimagesize($chosen);
header("Content-type: {$size['mime']}");
readfile($chosen);
?>

Grtz,
 
D

Dave Kelly

Rik said:
I know that EV1 runs PHP because I have the SMF code running. I just
need to check and see what hooks to scheduling they have.

HTML: <img src="/path/to/dir/random.php" />

random.php:
<?php

$dh = opendir(dirname(__FILE__));

$images = array();
$img_extensions = array('jpeg','jpg','png','gif');

while (($file = readdir($dh))!==false){
if(is_file(dirname(__FILE__).'/'.$file)){
preg_match('/([^.]*)$/si',$file,$matches);
if(in_array(strtolower($matches[1]),$img_extensions)){
$images[] = $file;
}
}
}
closedir($dh);
$chosen ='./'.$images[rand(0,count($images)-1)];
$size = getimagesize($chosen);
header("Content-type: {$size['mime']}");
readfile($chosen);
?>

Grtz,

I did not intend for you to do my work for me, but since you were kind
enough. THANK YOU.
 
R

Rik

Dave said:
Rik said:
I know that EV1 runs PHP because I have the SMF code running. I just
need to check and see what hooks to scheduling they have.

HTML: <img src="/path/to/dir/random.php" />

random.php:
<?php

$dh = opendir(dirname(__FILE__));

$images = array();
$img_extensions = array('jpeg','jpg','png','gif');

while (($file = readdir($dh))!==false){
if(is_file(dirname(__FILE__).'/'.$file)){
preg_match('/([^.]*)$/si',$file,$matches);
if(in_array(strtolower($matches[1]),$img_extensions)){
$images[] = $file;
}
}
}
closedir($dh);
$chosen ='./'.$images[rand(0,count($images)-1)];
$size = getimagesize($chosen);
header("Content-type: {$size['mime']}");
readfile($chosen);
Grtz,

I did not intend for you to do my work for me, but since you were
kind enough. THANK YOU.

No problem, pretty much cut'n'paste from existing code here, took less time
then trying to describe it :).

Grtz,
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,767
Messages
2,569,572
Members
45,046
Latest member
Gavizuho

Latest Threads

Top