\n"; if ($imgnum > $pageimgs) { $pagenumberminus = $imgnum - $pageimgs; $linkpageminus = makethumblink ($pagenumberminus); $linktext .= "< - previous thumb page - "; } if ($imgnum < ($imgcount - $pageimgs + 1)) { $linknumplus = makethumblink ($imgnumplus); $linktext .= "- next thumb page - > "; } $pagenumber = 1; $linktext .= "

\n"; $linktext .= "thumbnail page for images: | "; while ($pagenumber <= $imgcount) { $linkpagenumber = makethumblink ($pagenumber); if (($pagenumber + $pageimgs - 1) <= $imgcount) { $pagenumberplus = $pagenumber + $pageimgs - 1; } else { $pagenumberplus = $imgcount; } $linktext .= "$pagenumber-$pagenumberplus | "; $pagenumber = $pagenumberplus + 1; } return $linktext; } function minsecform ($sec) { if ($sec > 60) { $min = floor ($sec / 60); if ($min != 1) { $sm = "s"; } $minstr = "$min minute$sm "; $sec = $sec % 60; } if ($sec != 1) { $ss = "s"; } $minsecstring = "$minstr$sec second$ss"; return $minsecstring; } function makethumblink ($num) { global $htmlgen; if ($htmlgen == "TRUE") { if ($num == "1") { $num = ""; } $linkselfindex = "index$num.html"; } else { $linkselfindex = "$phpself?imgnum=$num"; } return $linkselfindex; } function filenamedisplay ($filename, $webtitle, $imgnum) { global $pageimgs, $htmlgen, $bgcolord, $textd, $linkd, $vlinkd, $font, $pageheader, $pagefooter; $imgcount = 0; $imgnumplus = $imgnum + $pageimgs; $imgnumminus = $imgnum - $pageimgs; $funcval = ""; $funcval .= " \n\n\n$webtitle - $filename\n \n"; $funcval .= ""; $funcval .= "\n
\n"; if ($pageheader != "") { $funcval .= "$pageheader
\n"; } $handle = opendir('.'); $cnt = 0; $linkarray[0] = ""; $fileindir = false; while (false !== ($file = readdir($handle))) { if ((substr ($file, 0, 1)) != "." && $file != "..") { $filearray = filenamecheck ($file); if ($filearray['web']) { $cnt++; $imgcount++; if ($htmlgen == "TRUE") { $htmlfilename = $filearray['left'] . ".html"; } if ($imgcount == ($imgnum - 1)) { if ($htmlgen) { $linkarray[$cnt] = "$cnt"; } else { $linkarray[$cnt] = "$cnt"; } } if ($imgcount == $imgnumplus) { if ($htmlgen) { $linkarray[$cnt] = "$cnt"; } else { $linkarray[$cnt] = "$cnt"; } } if ($imgcount >= $imgnum && $imgcount < $imgnumplus) { if ($htmlgen) { $linkarray[$cnt] = "$cnt"; } else { $linkarray[$cnt] = "$cnt"; } } #was inside of above if if ($filename == $file) { $amcnt = $cnt; $fileindir = true; } } } } closedir($handle); $cnt++; $linkarray[$cnt] = ""; $amcnt1 = $amcnt - 1; $amcnt3 = $amcnt + 1; $linkselfindex = makethumblink ($imgnum); $prevnext = "<-- $linkarray[$amcnt1] | index | $linkarray[$amcnt3] -->"; $links = implode (" | ", $linkarray); $funcval .= "$prevnext

\n"; #add check for filename in dir if ($fileindir) { $size = GetImageSize ($filename); $funcval .= "\"$filename\n"; } else { $funcval .= "Error: filename supplied not in directory.
\n"; } $funcval .= "

"; $funcval .= "$filename

\n"; $funcval .= "$prevnext

\n"; $funcval .= "$links

\n"; $funcval .= bottomlinks ($imgcount, $imgnum); $funcval .= "\n

\n"; $funcval .= $pagefooter; $funcval .= "
\n\n"; if ($htmlgen == "TRUE") { $filearray = filenamecheck ($filename); $htmlfilename = $filearray['left'] . ".html"; $fp = fopen ($htmlfilename, "wb"); fwrite ($fp, $funcval); fclose ($fp); } return $funcval; } function makeindex ($imgnum, $webtitle, $mgk, $reduce, $stripexif, $goall, $max, $thumbmax, $dorotate, $jpegquality, $inputindicator) { global $phpself, $phpfile, $phpdir, $pageimgs, $htmlgen, $thumbdir, $thumbmax, $thumbmaxdefault, $reducedefaultmax, $jpegqualitydefault, $localjpegtran, $localconvert, $rotate, $totalcount, $starttime, $start, $submit, $retime, $bgcolori, $texti, $linki, $vlinki, $font, $columns, $pageheader, $pagefooter, $rotatechecked, $htmlgenchecked, $reducechecked, $stripexifchecked, $uri, $redirecturl; $imgcount = 0; $imgnumplus = $imgnum + $pageimgs; $imgnumminus = $imgnum - $pageimgs; if (!$timeouts) { $timeouts = 360; } $handle = opendir('.'); $indextext1 = " $webtitle Page $imgnum "; $indextext1 .= "\n"; $indextext = ""; if ($dorotate == "TRUE") { $indextext .= "Select the button on the right side of an image to rotate 90° clockwise,
\n"; $indextext .= "Select the button on the left side of an image to rotate 90° counterclockwise,
\n"; $indextext .= "Select the button on the bottom of an image to rotate 180°.
\n"; $indextext .= "Leaving the button on 0° will leave the image unrotated.
\n"; $indextext .= "Click 'Rotate Images' at the bottom of the page to execute your rotation selections.
\n"; $indextext .= "
\n"; } else if ($dorotate == "GO") { #$indextext .= "If you have rotated images, you may need to click here to see the updated images.
\n"; #$indextext .= "Reload the next page if you still don't see the updated images, do not reload this page, or your images may rotate again.
\n"; $imgcountrotate = 0; $tempimgnum = 1; while (list ($key, $val) = each ($rotate)) { $imgcountrotate++; if ($imgcountrotate >= ($tempimgnum + $pageimgs)) { $tempimgnum = $tempimgnum + $pageimgs; } if ($val != "0") { if (is_writable ($key)) { $rotatee = array($key, "thumbs/t_$key"); while (list ($key1, $val1) = each ($rotatee)) { $command = "$localjpegtran -rotate $val -trim -copy all $val1 > $val1-temp"; #$indextext .= $command; $execresult = exec ($command); copy("$val1-temp", $val1); unlink("$val1-temp"); #redo the html? #let's try writing the html here if ($htmlgen == "TRUE" && ((strstr($val1, "thumbs")) == FALSE)) { $filenamedisplaytext = filenamedisplay ($val1, $webtitle, $tempimgnum); #$indextext .= $filenamedisplaytext; } #end of try writing html } } else { $indextext .= "file: $key is not writable, change permissions to enable reduction, must be writable by everyone, you can hit back on your browser and try again after changing permissions (you can change permissions back when done if you are concerned)
\n"; } } } } $indextext .= "\n"; if ($pageheader != "") { $indextext .= "\n"; } $indextext .= "\n"; $cnt = -1; $tempimgnum = 1; while (false !== ($file = readdir($handle))) { if ((substr ($file, 0, 1)) != "." && $file != "..") { set_time_limit($timeouts); $filearray = filenamecheck ($file); if ($filearray['web']) { $farray[] = $file; } } } closedir($handle); $totalfilecount = count ($farray); #new looper while (list ($key, $file) = each ($farray)) { $imgcount++; if ($imgcount >= ($tempimgnum + $pageimgs)) { $tempimgnum = $tempimgnum + $pageimgs; } $filearray = filenamecheck ($file); if (($imgcount >= $imgnum && $imgcount < $imgnumplus) || ($goall == "TRUE")) { $cnt++; if ($cnt == $columns) { $indextext .= "\n\n"; $cnt = 0; } $indextext .= "\n
\n"; $indextext .= "$pageheader
\n"; $indextext .= "
"; $namestuff = "$file"; $filethumbbase = $thumbdir . "/t_" . $filearray['left']; $filethumb = $filethumbbase . "." . $filearray['right']; if (!(file_exists($filethumb))) { umask(0000); if (!(is_writable ("."))) { $indextext .= "
"; $indextext .= "note: this directory is not writable, change permissions to enable thumbnail creation
\n"; $indextext .= "
"; echo $indextext1 . $indextext; exit; } if (!(file_exists($thumbdir))) { if (!(mkdir ($thumbdir, 0777))) { $indextext .= "\n"; $indextext .= "Couldn't make $thumbdir, check directory permissions."; $indextext .= ""; echo $indextext1 . $indextext; exit; } } if (!isset($mgk)) { if ($localconvert != "") { if ($reducechecked) { $reducecheckedstr = "checked"; } if ($stripexifchecked) { $stripexifcheckedstr = "checked"; } $imagemagickexist = ""; $imagemagickexistreduce = ""; $imagemagickexiststripexif = ""; } else { $imagemagickexist = "(ImageMagick not installed)"; $imagemagickexistreduce = "(ImageMagick not installed)"; $imagemagickexiststripexif = "(ImageMagick not installed)"; $phpgdexistfallback = " CHECKED"; } if (($localjpegtran != "")) { if ($rotatechecked) { $dorotatechecked = "checked"; } $jpegtranexist = ""; } else { $jpegtranexist = "(jpegtran not installed)"; } if (function_exists(ImageCreateFromJPEG)) { $phpgdexist = ""; } else { $phpgdexist = " / (php gd lib does not support jpeg)"; } if (($localconvert != "") || function_exists(ImageCreateFromJPEG)) { $somethumbmethodexist = ''; } else { $somethumbmethodexist = "(Install ImageMagick or PHP with GD library to make thumbs)"; } $specform = ""; $specform .= "\n"; $specform .= "Method for thumbnail creation: $imagemagickexist Image Magick $phpgdexist PHP
\n"; $specform .= "Maximum dimension of thumbnail
\n"; $specform .= "$imagemagickexistreduce Reduce large images
\n"; $specform .= "$imagemagickexiststripexif Strip EXIF data when reducing
\n"; $specform .= "Maximum dimension of reduced image
\n"; $specform .= "Quality of ImageMagick JPEGs, 0 (lowest) to 100 (highest)
\n"; $specform .= " Do all images in Directory
\n"; $specform .= "$jpegtranexist Rotate selected images after processing
\n"; $specform .= "\n"; $specform .= $somethumbmethodexist; if ($htmlgenchecked) { $htmlgencheckedstr = "checked"; } $specform .= "

Generate static HTML pages
\n"; $specform .= "

\n"; $indextext .= "\n"; $indextext .= $specform; $indextext .= $inputindicator; if (!(is_writable ($file))) { $indextext .= "note: $file is not writable, change permissions to enable ImageMagick reduction or JPEG Rotation
\n"; } if (!(is_writable ("thumbs"))) { $indextext .= "note: the thumbs directory is not writable, change permissions to enable thumbnail creation
\n"; } $indextext .= ""; echo $indextext1 . $indextext; exit; } # if $mgk will try to use ImageMagick if ($mgk == "TRUE") { if ($reduce || $filearray['convert']) { if (!(is_writable ($file))) { $indextext .= "file: $file is not writable, change permissions to enable reduction"; echo $indextext; exit; } #if tif, fileuse is same name but with .jpg if ($filearray['convert']) { $fileuse = $filearray['left'] . ".jpg"; $dupetifcount = 0; $filethumboriginal = $filethumb; while (file_exists($fileuse)) { $dupetifcount++; $fileuse = $filearray['left'] . "_" . $dupetifcount . ".jpg"; $filethumb = $filethumbbase . "_" . $dupetifcount . ".jpg"; } } else { $fileuse = $file; } #plain convert if not reduce, otherwise geometry if (!$reduce) { $maxmax = ""; } else { $maxmax = "-geometry '$max" . "x$max>'"; } #strip exif and profile info? if (!$stripexif) { $stripexifstr = ""; } else { $stripexifstr = "+profile '*'"; } $command = "$localconvert -quality $jpegquality $maxmax $stripexifstr $file $fileuse"; #$command = "$localconvert -geometry $max" . "x$max $file $file"; #echo $command; $execresult = exec ($command); #echo "res: $execresult"; $resultfilesize = filesize ($fileuse); if (($resultfilesize > 0) && $file != $fileuse) { unlink ($file); $file = $fileuse; $filethumb = ereg_replace (($filearray['right'] . '$'), "jpg", $filethumb); } } #$command = "/usr/local/bin/convert -geometry $thwidth" . "x$thheight $file $filethumb"; $command = "$localconvert -quality $jpegquality -geometry $thumbmax" . "x$thumbmax +profile '*' $file $filethumb"; #echo $command; $execresult = exec ($command); #echo ".result($execresult)"; } else { $origsize = GetImageSize ($file); $imWidth = $origsize[0]; $imHeight = $origsize[1]; if ($imWidth > $imHeight) { $thwidth = $thumbmax; $thheight = round (($thumbmax / $imWidth) * $imHeight); } else { $thheight = $thumbmax; $thwidth = round (($thumbmax / $imHeight) * $imWidth); } $im2 = ImageCreateFromJPEG ($file); $imt = ImageCreateTrueColor ($thwidth,$thheight); ImageCopyResampled ($imt, $im2, 0, 0, 0, 0, $thwidth, $thheight, $imWidth, $imHeight); ImageDestroy($im2); ImageJPEG($imt, $filethumb, 50); ImageDestroy($imt); } $namestuff .= "
$filethumb"; #let's try writing the html here if ($htmlgen == "TRUE") { #echo "imgcount $imgcount tempimgnum $tempimgnum | "; $filenamedisplaytext = filenamedisplay ($file, $webtitle, $tempimgnum); } #end of try writing html } # do thumbs $size = GetImageSize ($filethumb); if ($dorotate == "TRUE") { $indextext .= "
"; $indextext .= ""; } if ($htmlgen == "TRUE") { $filelink = $filearray['left'] . ".html"; } else { $filelink = "$phpself?filename=$file&imgnum=$imgnum"; } $indextext .= "\"$file"; if ($dorotate == "TRUE") { $indextext .= "
"; $indextext .= "180°
"; } $indextext .= "
$namestuff"; $indextext .= "\n"; } # try this redirect after time x to keep from timeout $timenow = time(); $uristart = !strstr($uri,"&start="); $timelapse = $timenow - $starttime; if ((($timelapse > $retime) || ($uristart)) && ($submit == "make thumbs")) { $redirecturl .= $uri; if ($uristart) { $redirecturl .= "&start=$start"; } #header("Location: $redirecturl"); $ttime = $timenow - $start; if ($ttime == 0) { $ttime = 1; } $pimages = $imgcount / $totalfilecount; $ttestimate = ceil ($ttime / $pimages); $tlestimate = $ttestimate - $ttime; $ttestimatestr = minsecform ($ttestimate); $tlestimatestr = minsecform ($tlestimate); $ttimestr = minsecform ($ttime); echo "$imgcount of $totalfilecount images completed in $phpdir\n"; echo "\n"; echo "\n"; echo "\nEstimated total time to complete: $ttestimatestr
Estimated time remaining: $tlestimatestr
\n"; echo "$imgcount of $totalfilecount images completed in $ttimestr
Working, Please Wait...."; echo "\n"; exit; } } #end new looper while ($cnt < 3) { $indextext .= "\n"; $cnt++; } $indextext .= "\n\n"; if ($dorotate == "TRUE") { $indextext .= ""; $indextext .= ''; $indextext .= ''; $indextext .= ''; $indextext .= "\n"; } $indextext .= bottomlinks ($imgcount, $imgnum); # echo $imgcount; $totalcount = $imgcount; if ($submit == "make thumbs") { $ttime = $timenow - $start; $ttimestr = minsecform ($ttime); $timeper = round (($ttime / $totalfilecount), 1); $timeperstr = minsecform ($timeper); $indextext1 .= "
\n$totalfilecount images done in $ttimestr (about $timeperstr per image)

\n"; } $indextext .= $pagefooter; $indextext .= "\n\n"; $indextext = $indextext1 . $indextext; return $indextext; } # full path to jpegtran command if (file_exists("/usr/local/bin/jpegtran")) { $localjpegtran = "/usr/local/bin/jpegtran"; } else if (file_exists("/usr/bin/jpegtran")) { $localjpegtran = "/usr/bin/jpegtran"; } else { $localjpegtran = ""; } # full path to ImageMagick convert command if (file_exists("/usr/local/bin/convert")) { $localconvert = "/usr/local/bin/convert"; } else if (file_exists("/usr/bin/convert")) { $localconvert = "/usr/bin/convert"; } else if (file_exists("/usr/local/ImageMagick/bin/convert")) { $localconvert = "/usr/local/ImageMagick/bin/convert"; } else { $localconvert = ""; } #check php version for ugly pre 4.1.0 fix $version = phpversion(); $versionnum = (double) (substr($version, 0, 3)); if ($versionnum < 4.1) { $oldversion = true; } else { $oldversion = false; } if ($oldversion) { $postvariable = "HTTP_POST_VARS"; $getvariable = "HTTP_GET_VARS"; $servervariable = "HTTP_SERVER_VARS"; } else { $postvariable = "_POST"; $getvariable = "_GET"; $servervariable = "_SERVER"; } $phpself = ${$servervariable}['PHP_SELF']; $phpfile = ${$servervariable}['SCRIPT_FILENAME']; $uri = ${$servervariable}['REQUEST_URI']; $protocol = "http"; if (${$servervariable}[HTTPS] == "on") { $protocol .= "s"; } $redirecturl = $protocol . "://" . ${$servervariable}['HTTP_HOST']; $webtitle = htmlentities($webtitle); $pageheader = htmlentities($pageheader); $pageheader = "$pageheader"; $pagefootertext = htmlentities($pagefootertext); if (($pagefootertext != "") || ($pagefooterlink != "")) { if ($pagefootertext == "") { $pagefootertext = $pagefooterlink; } if ($pagefooterlink == "") { $pagefooter = $pagefootertext; } else { $pagefooter = "$pagefootertext"; } $pagefooter = "

$pagefooter
\n"; } else { $pagefooter = ""; } if (${$postvariable}["submit"]) { $posts = array ("dorotate","htmlgen","submit"); while (list ($key, $val) = each ($posts)) { if (${$postvariable}[$val]) { $$val = ${$postvariable}[$val]; } } while (list ($key, $val) = each (${$postvariable}["rotate"])) { $rotate[$key] = $val; } } if (isset(${$getvariable})) { $gets = array ("mgk","reduce","stripexif","goall","max","thumbmax","jpegquality","imgnum","dorotate","start","htmlgen","submit"); while (list ($key, $val) = each ($gets)) { if (${$getvariable}[$val]) { $$val = ${$getvariable}[$val]; } } } if (!$max) { $max = $reducedefaultmax; } if (!$thumbmax) { $thumbmax = $thumbmaxdefault; } if (!$imgnum) { $imgnum = 1; } if (!$start) { $start = $starttime; } if (${$getvariable}['filename']) { $filename = ${$getvariable}['filename']; $filenamedisplaytext = filenamedisplay ($filename, $webtitle, $imgnum); echo $filenamedisplaytext; exit; } $inputindicator = ""; $validate = array(array("jpegquality","JPEG Quality",1,100), array("max","image dimension",10,8192), array("thumbmax","thumbnail dimension",10,999)); while (list ($key, $val) = each ($validate)) { if (isset(${$val[0]})) { if (!(is_numeric(${$val[0]})) || (${$val[0]} <= $val[2]) || (${$val[0]} >= $val[3])) { unset($mgk); unset($dorotate); $inputindicator .= "'${$val[0]}' is not a valid value for $val[1].
Please enter a number from $val[2] to $val[3]


\n"; } } } $indextextreturned = makeindex ($imgnum, $webtitle, $mgk, $reduce, $stripexif, $goall, $max, $thumbmax, $dorotate, $jpegquality, $inputindicator); echo $indextextreturned; if ($htmlgen == "TRUE") { $mgk = ""; $reduce = ""; $stripexif = ""; $goall = ""; $max = ""; $imgnum = ""; $dorotate = ""; $max = ""; $submit = ""; $pagenumber = 1; while ($pagenumber <= $totalcount) { $indextextreturned = makeindex ($pagenumber, $webtitle, $mgk, $reduce, $stripexif, $goall, $max, $thumbmax, $dorotate, $jpegquality, $inputindicator); if ($pagenumber == "1") { $pagenumberuse = ""; } else { $pagenumberuse = $pagenumber; } $htmlfilename = "index$pagenumberuse.html"; $fp = fopen ($htmlfilename, "wb"); fwrite ($fp, $indextextreturned); fclose ($fp); $pagenumber = $pagenumber + $pageimgs; } } ?>