Blame | Last modification | View Log | Download
<?php/*************************Coppermine Photo Gallery************************Copyright (c) 2003-2005 Coppermine Dev Teamv1.1 originaly written by Gregory DEMARThis program is free software; you can redistribute it and/or modifyit under the terms of the GNU General Public License as published bythe Free Software Foundation; either version 2 of the License, or(at your option) any later version.********************************************Coppermine version: 1.3.3$Source: /cvsroot/coppermine/stable/include/imageObjectGD.class.php,v $$Revision: 1.5 $$Author: gaugau $$Date: 2005/04/19 03:17:11 $**********************************************/class imageObject{// image resourcevar $imgRes;// pxvar $height=0;var $width=0;// for img height/width tagsvar $string;// output report or error messagevar $message;// file + dirvar $directory;var $filename;// output quality, 0 - 100var $quality;// truecolor available, booleanvar $truecolor;//constructorfunction imageObject($directory,$filename,$previous=null){$this->directory = $directory;$this->filename = $filename;$this->previous = $previous;$this->imgRes = $previous->imgRes;if (file_exists($directory.$filename)){$this->filesize = round(filesize($directory.$filename)/1000);if($this->filesize>0){$size = @GetImageSize($directory.$filename);if ($size && !$this->imgRes) {$this->imgRes = $this->getimgRes($directory.$filename,$size[2]);}if (function_exists("imagecreatetruecolor")){$this->truecolor = true;}$this->width = $size[0];$this->height = $size[1];$this->string = $size[3];}}// if}// constructor// private methodsfunction getimgRes($name,&$type){switch ($type){case 1:$im = imagecreatefromgif($name);break;case 2:$im = imagecreatefromjpeg($name);break;case 3:$im = imagecreatefrompng($name);break;}return $im;}function createUnique(&$imgnew){srand((double)microtime()*100000);$unique_str = "temp_".md5(rand(0,999999)).".jpg";@imagejpeg($imgnew,$this->directory.$unique_str,$this->quality);@imagedestroy($this->imgRes);//Don't clutter with old images@unlink($this->directory.$this->filename);//Create a new ImageObjectreturn new imageObject($this->directory,$unique_str,$imgnew);}function createImage($new_w,$new_h){if (function_exists("imagecreatetruecolor")){$retval = @imagecreatetruecolor($new_w,$new_h);}if (!$retval) $retval = imagecreate($new_w,$new_h);return $retval;}function cropImage(&$clipval){$cliparray = split(",",$clipval);$clip_top = $cliparray[0];$clip_right = $cliparray[1];$clip_bottom = $cliparray[2];$clip_left = $cliparray[3];$new_w = $clip_right - $clip_left;$new_h = $clip_bottom - $clip_top;$dst_img = $this->createImage($new_w,$new_h);$result = @imagecopyresampled($dst_img, $this->imgRes, 0,0,$clip_left, $clip_top,$new_w, $new_h, $new_w, $new_h);if (!$result) $result = @imagecopyresized($dst_img, $this->imgRes, 0,0,$clip_left, $clip_top,$new_w, $new_h, $new_w, $new_h);return $this->createUnique($dst_img);}function rotateImage(&$angle){if ($angle == 180){$dst_img = @imagerotate($this->imgRes, $angle, 0);}else{$width = imagesx($this->imgRes);$height = imagesy($this->imgRes);if ($width > $height){$size = $width;}else{$size = $height;}$dst_img = $this->createImage($size, $size);imagecopy($dst_img, $this->imgRes, 0, 0, 0, 0, $width, $height);$dst_img = @imagerotate($dst_img, $angle, 0);$this->imgRes = $dst_img;$dst_img = $this->createImage($height, $width);if ((($angle == 90) && ($width > $height)) || (($angle == 270) && ($width < $height))){imagecopy($dst_img, $this->imgRes, 0, 0, 0, 0, $size, $size);}if ((($angle == 270) && ($width > $height)) || (($angle == 90) && ($width < $height))){imagecopy($dst_img, $this->imgRes, 0, 0, $size - $height, $size - $width, $size, $size);}}return $this->createUnique($dst_img);}function resizeImage($new_w=0,$new_h=0){$dst_img = $this->createImage($new_w,$new_h);$result = @imagecopyresampled($dst_img, $this->imgRes, 0, 0, 0, 0, $new_w, $new_h, $this->width,$this->height);if (!$result) $result = @imagecopyresized($dst_img, $this->imgRes, 0, 0, 0, 0, $new_w, $new_h, $this->width,$this->height);return $this->createUnique($dst_img);}function saveImage(){}}?>