image_type = $image_info[2]; if( $this->image_type == IMAGETYPE_JPEG ) { $this->image = imagecreatefromjpeg($filename); } elseif( $this->image_type == IMAGETYPE_GIF ) { $this->image = imagecreatefromgif($filename); } elseif( $this->image_type == IMAGETYPE_PNG ) { $this->image = imagecreatefrompng($filename); } } function save($filename, $image_type=IMAGETYPE_JPEG, $compression=75, $permissions=null) { if( $image_type == IMAGETYPE_JPEG ) { imagejpeg($this->image,$filename,$compression); } elseif( $image_type == IMAGETYPE_GIF ) { imagegif($this->image,$filename); } elseif( $image_type == IMAGETYPE_PNG ) { imagepng($this->image,$filename); } if( $permissions != null) { chmod($filename,$permissions); } } function output($image_type=IMAGETYPE_JPEG) { if( $image_type == IMAGETYPE_JPEG ) { imagejpeg($this->image); } elseif( $image_type == IMAGETYPE_GIF ) { imagegif($this->image); } elseif( $image_type == IMAGETYPE_PNG ) { imagepng($this->image); } } function getWidth() { return imagesx($this->image); } function getHeight() { return imagesy($this->image); } function resizeToHeight($height) { $ratio = $height / $this->getHeight(); $width = $this->getWidth() * $ratio; $this->resize($width,$height); } function resizeToWidth($width) { $ratio = $width / $this->getWidth(); $height = $this->getheight() * $ratio; $this->resize($width,$height); } function scale($scale) { $width = $this->getWidth() * $scale/100; $height = $this->getheight() * $scale/100; $this->resize($width,$height); } function resize($width,$height) { $new_image = imagecreatetruecolor($width, $height); imagecopyresampled($new_image, $this->image, 0, 0, 0, 0, $width, $height, $this->getWidth(), $this->getHeight()); $this->image = $new_image; } } #coded for #CMS - CMS Made Simple #by (c)2007 by Tina Keil (blackyfreud@gmail.com) #Version 1.0 - 26.06.2007 #This project's homepage is: http://cmsmadesimple.sf.net # #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 //settings - change them as you need define("USE_FRONTENDUSERS_MODULE", false); //do you use the frontenduser module? define("DELIVER_CHUNKED", true); //enable if you have trouble with large files //you can add or remove file types here as needed $allowed_filetypes = array('.pdf','.jpg','.gif','.png','.doc','.rtf','.xls'); ############ do not edit below unless you know what you're doing ########### @ini_set('zlib.output_compression', 'Off'); function redirect403 () { header("HTTP/1.0 403 Forbidden"); exit; } //check frontenduser module authentification if (USE_FRONTENDUSERS_MODULE == true) { require_once(dirname(__FILE__)."/include.php"); global $gCms; $feusers = $gCms->modules['FrontEndUsers']['object']; if ($feusers) { $uid = $feusers->LoggedInId(); $username = $feusers->LoggedInName(); if (empty($uid) or $uid==0 or empty($username)) { header("HTTP/1.0 403 Forbidden"); exit; } } } $decoded_link = base64_decode($_GET['id']); $data_parts = explode("&", $decoded_link); $pos = strrpos($decoded_link,"/")+1; $width = 0; $height = 0; $percent = 25; foreach($data_parts as $var) { if(strrpos($var, 'height') !== false) $height = intval(str_replace("height=", "", $var)); elseif(strrpos($var,'width') !== false) $width = intval(str_replace("width=", "", $var)); elseif(strrpos($var,'percentage') !== false) $percent = intval(str_replace("percent=", "", $var)); } if ($pos!=0) { //clean up the path and get rid of anything odd $decoded_link = str_replace("..","",$data_parts[0]); $filepath = stripslashes(strip_tags($decoded_link, $pos)); $filename = stripslashes(strip_tags(substr($decoded_link, $pos))); $extension = strrchr(strtolower($filename), "."); } else { redirect403(); } if (in_array($extension, $allowed_filetypes)==false) { redirect403(); } $image = new SimpleImage(); $image->load($filepath); if($width>0 || $height>0) { //$tn_image = new Thumbnail($filepath, $width, $height, $percentage); if ($width>0 && $height==0) $image->resizeToWidth($width); elseif($height>0 && $width==0) $image->resizeToHeight($height); else $image->resize($width,$height); }else{ //$tn_image = new Thumbnail($filepath, $width, $height, $percentage); $image->scale($percentage); } //echo $width; $image->output(); //exit; ?>