I found this script that lets me resize images on the server and save
the thumbnails in a seperate folder. the only problem is that this
script also generates a bunch of HTML screens which I dont need.
Can someone help me cut the script down to perform the function of
just resizing and saving the images and then displaying a simple HTML
text when finished. It doesnt need to generate web pages to show the
images....
Any help much appreciated:
<?
//////////////////////////////////////////////////////////////////////
/////////
// Martin's Photo Frame, v3.3
http://dougiamas.com/photoframe
//
// Displays a directory full of images (JPEG, PNG, GIF) simply and
easily.
// It will also create thumbnails and display JPEG comments if it
finds them.
// I am placing this script in the Public Domain - use it as you wish.
//
// Requirements: A web server with this software (note minimum
versions):
// - PHP 4.0.2 http://www.php.net
// - GD 1.8.3 http://www.boutell.com/gd
// - libjpeg 6b ftp://ftp.uu.net/graphics/jpeg/
//
// How to use: 1. Store all your images in a directory on your
server
// 2. Save this file in that directory as index.php
// 3. Make sure the web server has write permissions so
// that it can create a sub directory for thumbnails.
// eg mkdir thumb ; chown nobody thumb
// (optional) 4. Change any of the settings below to suit.
// (optional) 5. Add an intro.html file if you like.
// (optional) 6. Add header.html and footer.html files if you want
// to change page colours, layout or styles.
// (optional) 7. Add a sortfile if you want to control the order
of
// the photos, rather than the default alphabetical
order.
// Just make a simple text file with one filename
per line.
// eg ls -1 .jpg .png > sortfile
// (and then edit with vi)
//
//////////////////////////////////////////////////////////////////////
/////////
//
// Default Settings - change here or create a config.php that
overrides them
// If using a config.php make sure you put PHP tags around the lines
of code
$title = "My Photo Album"; // Title for the overall web page
$marginsize = 150; // Size of left-hand frame with
thumbnails
$pagecolor = "#FFFFFF"; // Default background color of
pages
$textcolor = "#000000"; // Default text color for all
pages
$imagesize = false; // Resize images to fit window?
true/false
$thumb = "./thumb"; // Directory where thumbnails are
stored
$getcomment = "/usr/bin/rdjpgcom"; // To extract JPG comments (part
of libjpeg)
$introfile = "intro.html"; // If it exists, will be
displayed up front
$headerfile = "header.html"; // If it exists, will be included
at top
$footerfile = "footer.html"; // If it exists, will be included
at bottom
$sortfile = "sortfile"; // If it exists, contains
filenames in order
if (file_exists("config.php")) { // Settings in here will override
defaults
include("config.php");
}
//////////////////////////////////////////////////////////////////////
/////////
if (!function_exists("ImageTypes")) {
PrintHeader();
echo "<H3 align=center>Sorry, but this script requires that your
copy of PHP has been compiled with support for images.</H3>";
echo "<H3 align=center>configure --with-gd ...</H3>";
exit;
}
function RemoveNewLines (&$item, $key) {
$item = chop($item);
}
function GetFileList( $dirname="." ) { // Finds all the images
// First check to see if there's a file called $sortfile
// that contains a sorted list of filenames, one per line
// otherwise, will default to all files in alphabetical order
global $sortfile;
$files = array();
if (file_exists($sortfile)) {
$files = file($sortfile);
array_walk($files, 'RemoveNewLines');
} else {
$dir = opendir( $dirname );
while( $file = readdir( $dir ) ) {
if (eregi(".jpe?g$", $file) ||
eregi(".gif$", $file) ||
eregi(".png$", $file)) {
$files[] = $file;
}
}
sort($files);
}
return $files;
}
function GetNeighbours($imagelist, $currimage, &$previmage,
&$nextimage) {
// For a given image, return the next and previous ones
$lastimage = count($imagelist) - 1;
for ( $i=0; $i<=$lastimage; $i++) {
if ($imagelist[$i] == $currimage) {
if ($i == 0) {
$nextimage = $imagelist[$i+1];
$previmage = NULL;
return;
} else if ($i == $lastimage) {
$previmage = $imagelist[$i-1];
$nextimage = NULL;
return;
} else {
$previmage = $imagelist[$i-1];
$nextimage = $imagelist[$i+1];
return;
}
}
}
$previmage = NULL;
$nextimage = NULL;
return;
}
function PrintHeader() {
global $headerfile;
global $pagecolor;
global $textcolor;
if (file_exists($headerfile)) {
include($headerfile);
} else {
echo "<BODY BGCOLOR=\"$pagecolor\" TEXT=\"$textcolor\">\n";
}
}
function PrintFooter() {
global $footerfile;
global $title;
if (file_exists($footerfile)) {
include($footerfile);
} else {
echo "<CENTER><BR><P><FONT SIZE=-1>";
echo "<A TARGET=top HREF=\"\" >$title</A></P>\n";
echo "<A TARGET=top HREF=\"http://dougiamas.com/photoframe/\"
function CleanFilename($filename) {
return str_replace(" ","%20",$filename);
}
function ReadImageFromFile($filename, $type) {
$imagetypes = ImageTypes();
switch ($type) {
case 1 :
if ($imagetypes & IMG_GIF)
return $im = ImageCreateFromGIF($filename);
break;
case 2 :
if ($imagetypes & IMG_JPEG)
return ImageCreateFromJPEG($filename);
break;
case 3 :
if ($imagetypes & IMG_PNG)
return ImageCreateFromPNG($filename);
break;
default:
return 0;
}
}
function WriteImageToFile($im, $filename, $type) {
switch ($type) {
case 1 :
return ImageGIF($im, $filename);
case 2 :
return ImageJpeg($im, $filename, 70);
case 3 :
return ImagePNG($im, $filename);
default:
return false;
}
}
function PrintSlideshowForm ($nextimage, $slide=0) {
$common = "index.php?image=$nextimage&slide=";
$options = array (1 => "1 seconds", 3 => "3 seconds", 5 => "5
seconds",
10 => "10 seconds", 20 => "20 seconds", 30
=> "30 seconds",
40 => "40 seconds", 50 => "50 seconds", 60 => "1
minute");
echo "<FORM NAME=auto>";
echo "<SELECT NAME=popup
onChange=\"window.location=document.auto.popup.options
[document.auto.popup.selectedIndex].value\">\n";
echo " <OPTION VALUE=\"javascript:void(0)
\">Slideshow...</OPTION>\n";
foreach ($options as $value => $label) {
echo " <OPTION VALUE=\"$common$value\"";
if ($value == $slide) {
echo " SELECTED";
}
if ($label) {
echo ">$label</OPTION>\n";
} else {
echo ">$value</OPTION>\n";
}
}
echo "</SELECT></FORM>";
}
if ($intro) { // Print initial info in main
frame
if (file_exists($introfile)) {
include($introfile);
} else {
PrintHeader();
echo "<CENTER><H1>$title</H1>";
echo "<P>Select images from the left</P>";
}
die;
}
if ($margin) { // Create a list of thumbnails
if (!file_exists($thumb)) {
if ( ! mkdir($thumb, 0755)) {
echo "Error: could not create thumb dir - check write
permissions";
die;
}
}
PrintHeader();
$imagelist = GetFileList();
while ( list($i,$image) = each ($imagelist) ) {
$thumbimage = $thumb."/".$image;
$thumb_exists = file_exists($thumbimage);
if (!$thumb_exists) { // Try to create the thumbnail
$size = GetImageSize($image);
$width = $size[0];
$height = $size[1];
$type = $size[2];
if ($im = ReadImageFromFile($image, $type)) {
$twidth = $margin - 20;
$theight = ($twidth / $width) * $height;
if (function_exists("ImageCreateTrueColor")) {
$im2 = ImageCreateTrueColor($twidth,$theight);
} else {
$im2 = ImageCreate($twidth,$theight);
}
if (function_exists("ImageCopyResampled"))
{
ImageCopyResampled
($im2,$im,0,0,0,0,$twidth,$theight,$width,$height);
} else {
ImageCopyResized
($im2,$im,0,0,0,0,$twidth,$theight,$width,$height);
}
if (WriteImageToFile($im2, $thumbimage, $type)) {
$thumb_exists = true;
}
}
}
$comment = Exec(EscapeShellCmd("$getcomment $image"));
if (! $comment) {
$comment = $image;
}
$image = CleanFilename($image);
$thumbimage = CleanFilename($thumbimage);
// The d=d.html was added to help dumb caches
echo "<A HREF=\"index.php?image=$image&d=d.html\"
TARGET=imain>";
if ($thumb_exists) {
echo "<IMG SRC=\"$thumbimage\" BORDER=0 ALT=\"$comment\">";
} else {
echo "<FONT SIZE=1>$comment</FONT>";
}
echo "</A><BR><BR>\n";
}
die;
}
if ($image) {
if (!file_exists($image)) {
echo "Error: Strangely, that picture doesn't exist";
die;
}
$imagelist = GetFileList();
GetNeighbours($imagelist, $image, $previmage, $nextimage);
if ($slide && $nextimage) {
echo "<HEAD><META HTTP-EQUIV=REFRESH
CONTENT=\"$slide;URL=index.php?
image=$nextimage&slide=$slide\"></HEAD>";
} else {
$slide = "0";
}
PrintHeader();
echo "<TABLE ALIGN=RIGHT CELLPADDING=0 CELLSPACING=0><TR>";
if ($previmage) {
echo "<TD><FONT SIZE=-1><FORM ACTION=\"index.php\">
<INPUT TYPE=hidden name=image value=$previmage>
<INPUT TYPE=submit VALUE=Prev></FORM></TD>";
}
if ($nextimage) {
echo "<TD><FONT SIZE=-1><FORM ACTION=\"index.php\">
<INPUT TYPE=hidden name=image value=$nextimage>
<INPUT TYPE=submit VALUE=Next></FORM></TD>";
echo "<TD><FONT SIZE=-1> ";
PrintSlideshowForm($nextimage, $slide);
echo "</TD>";
}
echo "</TR></TABLE>";
$comment = Exec(EscapeShellCmd("$getcomment $image"));
$image = CleanFilename($image);
echo "<H3 align=left>$comment</H3>";
if ($imagesize) {
$imagewidth = "WIDTH=100%";
}
echo "<BR CLEAR=ALL><CENTER><P><IMG $imagewidth
SRC=\"$image\"></P>";
PrintFooter();
die;
}
?>
<HEAD>
<TITLE><? echo $title ?></TITLE>
<META NAME="Description" CONTENT="Made with Martin's Photo Frame,
http://dougiamas.com/photoframe">
</HEAD>
<FRAMESET COLS="<? echo $marginsize ?>,*" BORDER=1>
<FRAME NAME=imargin SRC="index.php?margin=<? echo $marginsize ?>"
FRAMEBORDER=0
marginwidth="0" marginheight="0" noresize SCROLLING=AUTO>
<FRAME NAME=imain SRC="index.php?intro=1" FRAMEBORDER=0
SCROLLING=AUTO>
<NOFRAMES>
This site works best wih frames, which your browser doesn't
support.
You can still browse this photo album, though, by starting
<A HREF="index.php?margin=<? echo $marginsize ?>">here</A>
</NOFRAMES>
</FRAMESET>