Пример #1
0
/**
* Create a squared thumbnail from an existing image.
* 
* @param	string		$file		Location and name where the file is stored .
* @return	boolean
* @access	public
* @author	Christian Machmeier
*/
function createThumb($thisImagePath, $thisThumbnailPath)
{
    // Get information about the installed GD.
    $gdVersion = getGDversion();
    if ($gdVersion == false) {
        return false;
    }
    //$file = $imagePath.'/'.$albumName.'/'.$fileName;
    $file = $thisImagePath;
    //$fileDest = $thumbnailPath.'/'.$albumName.'/'.$fileName.'thumb';
    $fileDest = $thisThumbnailPath;
    //$fileDest = $thumbnailPath.'/'.$albumName.'/'.$fileName;
    //print $imagePath;
    //print $file . " to " . $fileDest . '<BR>';
    //print $fileDest;
    // Get the image dimensions.
    $dimensions = @getimagesize($file);
    $width = $dimensions[0];
    $height = $dimensions[1];
    $outputX = 50;
    $outputY = 50;
    $quality = 85;
    // The image is of vertical shape.
    if ($width < $height) {
        $deltaX = 0;
        $deltaY = ($height - $width) / 2;
        $portionX = $width;
        $portionY = $width;
        // The image is of horizontal shape.
    } else {
        if ($width > $height) {
            $deltaX = ($width - $height) / 2;
            $deltaY = 0;
            $portionX = $height;
            $portionY = $height;
            // The image is of squared shape.
        } else {
            $deltaX = 0;
            $deltaY = 0;
            $portionX = $width;
            $portionY = $height;
        }
    }
    $imageSrc = @imagecreatefromjpeg($file);
    // The thumbnail creation with GD1.x functions does the job.
    if ($gdVersion < 2) {
        // Create an empty thumbnail image.
        $imageDest = @imagecreate($outputX, $outputY);
        // Try to create the thumbnail from the source image.
        if (@imagecopyresized($imageDest, $imageSrc, 0, 0, $deltaX, $deltaY, $outputX, $outputY, $portionX, $portionY)) {
            // save the thumbnail image into a file.
            @imagejpeg($imageDest, $fileDest, $quality);
            // Delete both image resources.
            @imagedestroy($imageSrc);
            @imagedestroy($imageDest);
            return "<font face='arial, helvetica' size='small' color='#006633'>CREATED";
        }
    } else {
        // The recommended approach is the usage of the GD2.x functions.
        // Create an empty thumbnail image.
        $imageDest = @imagecreatetruecolor($outputX, $outputY);
        // Try to create the thumbnail from the source image.
        if (@imagecopyresampled($imageDest, $imageSrc, 0, 0, $deltaX, $deltaY, $outputX, $outputY, $portionX, $portionY)) {
            // save the thumbnail image into a file.
            @imagejpeg($imageDest, $fileDest, $quality);
            // Delete both image resources.
            @imagedestroy($imageSrc);
            @imagedestroy($imageDest);
            return "<font face='arial, helvetica' size='small' color='#006633'>CREATED";
        }
    }
    return "<font face='arial, helvetica' size='small' color='#FF0000'>ERROR";
}
    function install() {

      // SET GALLERY OPTIONS HERE
      // -----------------------
      // Set Gallery options by editing this text:

      $options .= '<simpleviewerGallery maxImageWidth="380" maxImageHeight="380" textColor="0x000000" frameColor="0x000000" frameWidth="5" stagePadding="5" thumbnailColumns="2" thumbnailRows="2" navPosition="right" title="OOS [Gallery]" enableRightClickOpen="false" backgroundImagePath="images/gallery.jpg" imagePath="gallery/images/" thumbPath="gallery/thumbs/">';

      // Set showDownloadLinks to true if you want to show a 'Download Image' link as the caption to each image.
      $showDownloadLinks = false;

      // set useCopyResized to true if thumbnails are not being created.
      // This can be due to the imagecopyresampled function being disabled on some servers
      $useCopyResized = false;

      // Set sortImagesByDate to true to sort by date. Otherwise files are sorted by filename.
      $sortImagesByDate = true;

      // Set sortInReverseOrder to true to sort images in reverse order.
      $sortInReverseOrder = true;

      // END OF OPTIONS
      // -----------------------

      $tgdInfo    = getGDversion();
      if ($tgdInfo == 0){
        // print "Note: The GD imaging library was not found on this Server. Thumbnails will not be created. Please contact your web server administrator.<br><br>";
        $error_gdlib = "Note: The GD imaging library was not found on this Server. Thumbnails will not be created. Please contact your web server administrator.";
        $messageStack->add($error_gdlib, 'error');
      }

      if ($tgdInfo < 2){
        // print "Note: The GD imaging library is version ".$tgdInfo." on this server. Thumbnails will be reduced quality. Please contact your web server administrator to upgrade GD version to 2.0.1 or later.<br><br>";
        $error_gdlib = "Note: The GD imaging library is version ".$tgdInfo." on this server. Thumbnails will be reduced quality. Please contact your web server administrator to upgrade GD version to 2.0.1 or later.";
        $messageStack->add($error_gdlib, 'error');
      }

/*
     if ($sortImagesByDate){
       print "Sorting images by date.<br>";
     } else {
       print "Sorting images by filename.<br>";
     }

     if ($sortInReverseOrder){
       print "Sorting images in reverse order.<br><br>";
     } else {
       print "Sorting images in forward order.<br><br>";
     }
*/


      //loop thru images
      $xml = '<?xml version="1.0" encoding="UTF-8" ?>'.$options;
      $folder = opendir(OOS_GALLERY_PATH ."images");
      while($file = readdir($folder)) {
        if ($file == '.' || $file == '..' || $file == 'CVS' || $file == '.svn') continue;

        if ($sortImagesByDate){
          $files[$file] = filemtime(OOS_GALLERY_PATH . "images/$file");
        } else {
          $files[$file] = $file;
        }
      }

      // now sort by date modified
      if ($sortInReverseOrder){
        arsort($files);
      } else {
        asort($files);
      }


      foreach($files as $key => $value) {
        $xml .= '
        <image>';
        $xml .= '<filename>'.$key.'</filename>';

        //add auto captions: 'Image X'
        if ($showDownloadLinks){
          $xml .= '<caption><![CDATA[<A href="images/'.$key.'" target="_blank"><U>Open image in new window</U></A>]]></caption>';
        }
        $xml .= '</image>';

        // print "- Created Image Entry for: $key<br>";

        if (!file_exists(OOS_GALLERY_PATH. "/thumbs/".$key)){
          if (createThumb($key)){
           // print "- Created Thumbnail for: $key<br>";
          }
        }
      }

      closedir($folder);

      $xml .= '</simpleviewerGallery>';

      $file = OOS_ABSOLUTE_PATH . 'gallery.xml';
      if (!$file_handle = fopen($file,"w")) {
        // print "<br>Cannot open XML document: $file<br>";
      } elseif (!fwrite($file_handle, $xml)) {
        // print "<br>Cannot write to XML document: $file<br>";
      } else {
        // print "<br>Successfully created XML document: $file<br>";
      }
      fclose($file_handle);

      return true;
    }
Пример #3
0
<?php

$imagePath = "albums";
//  path where you have the preview image tree (the large images in photofolio)  i.e. "seefile/images"
$thumbnailPath = "thumbnails";
//  path where you want the thumbnail tree  i.e. "../seefile home directory/thumbs"
//print "<head><title>Build Thumbnail Script<title></head>";
//print "<body>";
print "<font face='arial, helvetica' size='medium'><B>Creating thumbnails from original images. . .<B></font><br>";
print "<HR width='400' height='1' align='left'>";
//Get GD imaging library info
$tgdInfo = getGDversion();
if ($tgdInfo == 0) {
    print "Note: The GD imaging library was not found on this Server. Thumbnails will not be created. Please contact your web server administrator.<br><br>";
}
if ($tgdInfo < 2) {
    print "Note: The GD imaging library is version " . $tgdInfo . " on this server. Thumbnails will be reduced quality. Please contact your web server administrator to upgrade GD version to 2.0.1 or later.<br><br>";
}
print "<table  width='400' border='0' cellspacing='0' cellpadding='2'>";
//loop thru images
if (is_dir("{$thumbnailPath}") == 0) {
    mkdir("{$thumbnailPath}", 0777);
    print "<TR><TD align='left' colspan='2'><font face='arial, helvetica' size='small'><b>{$thumbnailPath} created</b> </font><br>";
}
parseFolder($imagePath, $thumbnailPath);
print "<TR><TD align='right' colspan='2'><font face='arial, helvetica' size='medium'><strong>Processing Complete.</strong></font></TD>";
print "</table>";
//print "</body>";
function parseFolder($tempFolderPath, $tempThumbnailPath)
{
    $dir = opendir("{$tempFolderPath}");