00001 <?php
00002
00003 class aliroImage {
00004 private $path = '';
00005 private $image = null;
00006
00007 public function __construct ($path) {
00008 $this->path = $path;
00009 $info = pathinfo($path);
00010 $type = $info['extension'];
00011 if ('jpg' == $type OR 'jpeg' == $type) $this->image = imagecreatefromjpeg($path);
00012 elseif ('png' == $type) $this->image = imagecreatefrompng($path);
00013 elseif ('gif' == $type) $this->image = imagecreatefromgif($path);
00014 else trigger_error (T_('Class aliroImage create - path has invalid extension - not jpg, jpeg, gif, png'), E_USER_ERROR);
00015 }
00016
00017
00018
00019 public function imgresize ($new_width, $new_height) {
00020 if (!$this->image) trigger_error (T_('Class aliroImage resize - no valid image created'), E_USER_ERROR);
00021
00022 $old_x=imagesx($this->image);
00023 $old_y=imagesy($this->image);
00024
00025
00026 $ratio = min($new_width/$old_x, $new_height/$old_y);
00027 $new_height = $old_y * $ratio;
00028 $new_width = $old_x * $ratio;
00029
00030
00031 $dst_img=ImageCreateTrueColor($new_width, $new_height);
00032
00033
00034 imagecopyresampled($dst_img, $this->image, 0, 0, 0, 0, $new_width, $new_height, $old_x, $old_y);
00035 }
00036
00037 public function saveAs ($path, $highQuality=false) {
00038 if (!$this->image) trigger_error (T_('Class aliroImage save - no valid image created'), E_USER_ERROR);
00039
00040 $info = pathinfo($path);
00041 $exts = array('jpg', 'jpeg', 'png', 'gif');
00042 if (in_array($info['extension'], $exts) {
00043 aliroFileManager::getInstance()->deleteFile($path);
00044 switch ($info['extension']) {
00045 case 'jpg':
00046 case 'jpeg':
00047 if ($highQuality) imagejpeg($this->image, $path, 100);
00048 else imagejpeg($this->image, $path);
00049 break;
00050 case 'png':
00051 if ($highQuality) imagepng($this->image, $path, 0);
00052 else imagepng($this->image, $path);
00053 break;
00054 case 'gif':
00055 imagegif($this->image, $path);
00056 break;
00057 }
00058 }
00059 else trigger_error(T_('Class aliroImage save method - path has wrong extension'), E_USER_ERROR);
00060 }
00061
00062 }
00063