Location: PHPKode > scripts > MiniGal Nano > createthumb.php
<?php
/*
MINIGAL NANO
- A PHP/HTML/CSS based image gallery script

This script and included files are subject to licensing from Creative Commons (http://creativecommons.org/licenses/by-sa/2.5/)
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")

MiniGal Nano is created by Thomas Rybak

Copyright 2010 by Thomas Rybak
Support: www.minigal.dk
Community: www.minigal.dk/forum

Please enjoy this free script!


USAGE EXAMPLE:
File: createthumb.php
Example: <img src="createthumb.php?filename=photo.jpg&amp;width=100&amp;height=100">
*/

if (eregi("jpg", $_GET['filename'])) header('Content-type: image/jpeg');
if (eregi("gif", $_GET['filename'])) header('Content-type: image/gif');
if (eregi("png", $_GET['filename'])) header('Content-type: image/png');

    if ($_GET['size'] == "") $_GET['size'] = 120; //
       $imgsize = GetImageSize($_GET['filename']);
       $width = $imgsize[0];
       $height = $imgsize[1];
      if ($width > $height) { // If the width is greater than the height it’s a horizontal picture
        $xoord = ceil(($width-$height)/2);
        $width = $height;      // Then we read a square frame that  equals the width
      } else {
        $yoord = ceil(($height-$width)/2);
        $height = $width;
      }
         $new_im = ImageCreatetruecolor($_GET['size'],$_GET['size']);
         if (eregi("jpg", $_GET['filename'])) $im = ImageCreateFromJPEG($_GET['filename']);
         if (eregi("gif", $_GET['filename'])) $im = ImageCreateFromGIF($_GET['filename']);
         if (eregi("png", $_GET['filename'])) $im = ImageCreateFromPNG($_GET['filename']);
         imagecopyresampled($new_im,$im,0,0,$xoord,$yoord,$_GET['size'],$_GET['size'],$width,$height);
         if (eregi("jpg", $_GET['filename'])) ImageJPEG($new_im,null,90);
         if (eregi("gif", $_GET['filename'])) ImageGIF($new_im,null,90);
         if (eregi("png", $_GET['filename'])) ImageJPEG($new_im,null,90);
?>
Return current item: MiniGal Nano