MiniGal Nano PHP Cross Reference Image Galleries

Source: /createthumb.php - 92 lines - 3454 bytes - Text - Print

   1  <?php
   2  /*
   3  MINIGAL NANO
   4  - A PHP/HTML/CSS based image gallery script
   5  
   6  This script and included files are subject to licensing from Creative Commons (http://creativecommons.org/licenses/by-sa/2.5/)
   7  You may use, edit and redistribute this script, as long as you pay tribute to the original author by NOT removing the linkback to www.minigal.dk ("Powered by MiniGal Nano x.x.x")
   8  
   9  MiniGal Nano is created by Thomas Rybak
  10  
  11  Copyright 2010 by Thomas Rybak
  12  Support: www.minigal.dk
  13  Community: www.minigal.dk/forum
  14  
  15  Please enjoy this free script!
  16  
  17  
  18  USAGE EXAMPLE:
  19  File: createthumb.php
  20  Example: <img src="createthumb.php?filename=photo.jpg&amp;width=100&amp;height=100">
  21  */
  22  //    error_reporting(E_ALL);
  23  
  24  if (preg_match("/.jpg$|.jpeg$/i", $_GET['filename'])) header('Content-type: image/jpeg');
  25  if (preg_match("/.gif$/i", $_GET['filename'])) header('Content-type: image/gif');
  26  if (preg_match("/.png$/i", $_GET['filename'])) header('Content-type: image/png');
  27  
  28      // Display error image if file isn't found
  29      if (!is_file($_GET['filename'])) {
  30          header('Content-type: image/jpeg');
  31          $errorimage = ImageCreateFromJPEG('images/questionmark.jpg');
  32          ImageJPEG($errorimage,null,90);
  33      }
  34      
  35      // Display error image if file exists, but can't be opened
  36      if (substr(decoct(fileperms($_GET['filename'])), -1, strlen(fileperms($_GET['filename']))) < 4 OR substr(decoct(fileperms($_GET['filename'])), -3,1) < 4) {
  37          header('Content-type: image/jpeg');
  38          $errorimage = ImageCreateFromJPEG('images/cannotopen.jpg');
  39          ImageJPEG($errorimage,null,90);
  40      }
  41      
  42      // Define variables
  43      $target = "";
  44      $xoord = 0;
  45      $yoord = 0;
  46  
  47      if ($_GET['size'] == "") $_GET['size'] = 120; //
  48         $imgsize = GetImageSize($_GET['filename']);
  49         $width = $imgsize[0];
  50         $height = $imgsize[1];
  51        if ($width > $height) { // If the width is greater than the height it’s a horizontal picture
  52          $xoord = ceil(($width-$height)/2);
  53          $width = $height;      // Then we read a square frame that  equals the width
  54        } else {
  55          $yoord = ceil(($height-$width)/2);
  56          $height = $width;
  57        }
  58  
  59      // Rotate JPG pictures
  60      if (preg_match("/.jpg$|.jpeg$/i", $_GET['filename'])) {
  61          if (function_exists('exif_read_data') && function_exists('imagerotate')) {
  62              $exif = exif_read_data($_GET['filename']);
  63              $ort = $exif['IFD0']['Orientation'];
  64              $degrees = 0;
  65              switch($ort)
  66              {
  67                  case 6: // 90 rotate right
  68                      $degrees = 270;
  69                  break;
  70                  case 8:    // 90 rotate left
  71                      $degrees = 90;
  72                  break;
  73              }
  74              if ($degrees != 0)    $target = imagerotate($target, $degrees, 0);
  75          }
  76      }
  77      
  78           $target = ImageCreatetruecolor($_GET['size'],$_GET['size']);
  79           if (preg_match("/.jpg$/i", $_GET['filename'])) $source = ImageCreateFromJPEG($_GET['filename']);
  80           if (preg_match("/.gif$/i", $_GET['filename'])) $source = ImageCreateFromGIF($_GET['filename']);
  81           if (preg_match("/.png$/i", $_GET['filename'])) $source = ImageCreateFromPNG($_GET['filename']);
  82           imagecopyresampled($target,$source,0,0,$xoord,$yoord,$_GET['size'],$_GET['size'],$width,$height);
  83           imagedestroy($source);
  84  
  85           if (preg_match("/.jpg$/i", $_GET['filename'])) ImageJPEG($target,null,90);
  86           if (preg_match("/.gif$/i", $_GET['filename'])) ImageGIF($target,null,90);
  87           if (preg_match("/.png$/i", $_GET['filename'])) ImageJPEG($target,null,90); // Using ImageJPEG on purpose
  88           imagedestroy($target);
  89  
  90  
  91  
  92  ?>

title

Description

title

Description

title

Description

title

title

Body