@mkdir('thumbs');
@chmod('thumbs',0711);
if(!is_dir('thumbs')) { die("Can't make 'thumbs' dir!
Try it manualy (note:
make it writable)"); }
function print_css() {
?>
}
function resizeimg($image) {
global $orig_image, $sm_image;
$cell_size = 240;
if(preg_match("/.[jJ][pP][gG]$|.[jJ][pP][eE][gG]/",$image)) {
$orig_image = imagecreatefromjpeg($image);
} elseif(preg_match("/.[pP][nN][gG]$/",$image)) {
$orig_image = imagecreatefrompng($image);
} elseif(preg_match("/.[gG][iI][fF]$/",$image)) {
$orig_image = imagecreatefromgif($image);
}
list($width, $height, $type, $attr) = getimagesize($image);
if( $width > $height ) { $max = $width; } else { $max = $height; }
$factor = ($max/100);
for($i=100;($i*$factor)>$cell_size;$i--) { $final = $i; }
$xsize = ($width/100)*$final;
$ysize = ($height/100)*$final;
$sm_image = imagecreatetruecolor($xsize,$ysize) or die ("Cannot Initial
ize new gd image stream");
Imagecopyresampled($sm_image,$orig_image,0,0,0,0,$xsize,$ysize,imagesx(
$orig_image),imagesy($orig_image));
}
function getImageDir($dirname) {
$dp = opendir($dirname) ;
// ignore everything except imgs :)
while ($f = readdir($dp)) {
if(preg_match("/.[jJ][pP][gG]$|.[jJ][pP][eE][gG]$|.[pP][nN][
gG]$|.[gG][iI][fF]$/",$f)) {
$imgs[] = $f;
}
}
// sort imgs by name...
sort($imgs);
return $imgs;
}
if (isset($_REQUEST['action']) && $_REQUEST['action'] == 'thumb') {
$image = $_GET['image'];
if(file_exists("thumbs/".$image)) {
if(filectime($image)>filectime("thumbs/".$image)) {
unlink("thumbs/".$image);
resizeimg($image);
imageJPEG($sm_image,"thumbs/".$image);
Header("Content-type: image/jpeg");
imageJPEG($sm_image);
} else {
$orig_image = imagecreatefromjpeg("thumbs/".$image);
Header("Content-type: image/jpeg");
imageJPEG($orig_image);
}
} else {
resizeimg($image);
imageJPEG($sm_image,"thumbs/".$image);
Header("Content-type: image/jpeg");
imageJPEG($sm_image);
}
if(isset($sm_image)) { imagedestroy($sm_image); }
if(isset($orig_image)) { imageDestroy($orig_image); }
exit;
}
if (isset($_REQUEST['action']) && $_REQUEST['action'] == 'slide') {
$image = $_GET['image'];
$imgs = getImageDir('.');
$imgcount = count($imgs);
$startimgnum = array_search($image,$imgs);
for($c=0;$c<$imgcount;$c=$c+12) {
if(($startimgnum >= $c) && ($startimgnum < ($c + 12))) {
$current = $c;
} else {
// something
}
}
$arkey = array_search ($image,$imgs);
if (!($arkey <= "0")) {
$prev_html = "Previous\n";
$prev = $_SERVER['PHP_SELF']."?action=slide&image=".$imgs[($ark
ey - 1)];
} else {
$prev = '';
}
$up_html = "Up\n";
$up = $_SERVER['PHP_SELF'];
if ($imgs[($arkey + 1)]) {
$next_html = "Next
\n";
$next = $_SERVER['PHP_SELF']."?action=slide&image=".$imgs[($arkey + 1)]
;
} else {
$next = '';
}
?>