<?php
/*
* Get thumbnail - really creates a thumbnail or retrieves existing one
*
* Copyright (c) 2003-4 St. Christopher House
*
* Developed by The Working Group Inc.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* @version $Id: getThumbnail.php,v 1.8 2005/01/24 20:32:21 cbooth7575 Exp $
*
*
* Notes:
*
* takes an image name and looks for it's thumbnail
* if it finds one, it returns that, as an image
* if it does not find one, it creates one and returns that
*
*/
define('CLN_FILE_BASE', '../../../');
$PAGETYPE = 'Admin';
include(CLN_FILE_BASE . 'index.php');
if (!defined('CLN_IMAGES_ROOT_DIR')) {
loadClass(CLN_IMAGE_MODID);
}
//**********************************************************************************
/*
*
* Function: noThumbailAvailable()
*
* returns no thumbnail available image
*
* @access public
* @return TBD
*
*/
function noThumbailAvailable() {
header("Content-type: image/png");
$im = @imagecreate(100, 50)
or die("Cannot Initialize new GD image stream");
$background_color = imagecolorallocate($im, 255, 255, 255);
$text_color = imagecolorallocate($im, 0, 0, 0);
imagestring($im, 10, 5, 5, "no", $text_color);
imagestring($im, 10, 5, 20, "thumbnail", $text_color);
imagestring($im, 10, 5, 35, "available", $text_color);
imagepng($im);
imagedestroy($im);
exit;
}
//**********************************************************************************
include("Image/Transform.php");
//define('IMAGE_TRANSFORM_LIB_PATH', '/usr/bin/');
//**********************************************************************************
// Main code
if(isset($_GET['filename'])) {
$sourcePath = CLN_FILE_BASE.CLN_IMAGES_ROOT_DIR;
//print $sourcePath."<br/>";
$destinationPath = CLN_FILE_BASE.CLN_IMAGES_ROOT_DIR.".thumbnail/";
//print $destinationPath."<br/>";
if(ereg("/([^\/]*$)",$_GET['filename'],$match)) {
$filename = $match[1];
//print $filename."<br/>";
}
// get type
if(ereg(".*\.([a-zA-Z0-9]*)",$_GET['filename'],$match)) {
$extension = $match[1];
} else {
noThumbailAvailable();
}
if(eregi("[jpeg|jpg]",$extension)) {
$type = "jpg";
}
else if(eregi("gif",$extension)) {
$type = "gif";
}
else if(eregi("png",$extension)) {
$type = "png";
}
else {
noThumbailAvailable(); // exits inside this function
}
// output image
header("Content-type: image/"+$type);
if(!file_exists($destinationPath.$filename)) {
$imageObj = Image_Transform::factory(CLN_IMAGE_MANIPULATION_LIBRARY);
$imageObj->load($sourcePath.$filename);
if(!($imageObj->getImageHeight() < CLN_IMAGE_THUMBNAIL_SIZE && $imageObj->getImageWidth() < CLN_IMAGE_THUMBNAIL_SIZE)) {
$imageObj->scaleMaxLength(CLN_IMAGE_THUMBNAIL_SIZE);
}
if(!is_dir($destinationPath)) {
$old = umask(0);
mkdir($destinationPath,0777);
copy($sourcePath."index.php",$destinationPath."index.php");
umask($old);
}
$imageObj->save($destinationPath.$filename);
}
// :QUESTION: why did i do this? - isn't it easier to just open the file and print it out? - dwc
$imageObj = Image_Transform::factory(CLN_IMAGE_MANIPULATION_LIBRARY);
$imageObj->load($destinationPath.$filename);
$imageObj->display();
clnWriteLog();
} else {
noThumbailAvailable();
}
?>