Exemplo n.º 1
-1
 private function _load_image($path)
 {
     list($w, $h, $type) = getimagesize($path);
     switch ($type) {
         case IMAGETYPE_GIF:
             $this->_format = 'gif';
             return imagecreatefromgif($path);
         case IMAGETYPE_JPEG:
             $this->_format = 'jpg';
             return imagecreatefromjpeg($path);
         case IMAGETYPE_PNG:
             $this->_format = 'png';
             return imagecreatefrompng($path);
         case IMAGETYPE_SWF:
             $this->_format = 'swf';
             return imagecreatefromswf($path);
         case IMAGETYPE_WBMP:
             $this->_format = 'wbmp';
             return imagecreatefromwbmp($path);
         case IMAGETYPE_XBM:
             $this->_format = 'xbm';
             return imagecreatefromxbm($path);
         default:
             return imagecreatefromstring(file_get_contents($path));
     }
     return false;
 }
Exemplo n.º 2
-1
 function loadImageFromFile($imageInfo)
 {
     $_result = 0;
     $filelocation = $imageInfo['file_location'];
     //$filelocation = dirname($this->_filename).'/'.$filelocation;
     switch ($imageInfo['type']) {
         case 1:
             $_result = @imagecreatefromgif($filelocation);
             break;
         case 2:
             $_result = @imagecreatefromjpeg($filelocation);
             break;
         case 3:
             $_result = @imagecreatefrompng($filelocation);
             break;
         case 4:
             $_result = @imagecreatefromswf($filelocation);
             break;
         case 6:
             $_result = @imagecreatefromwbmp($filelocation);
             break;
         case 15:
             $_result = @imagecreatefromxbm($filelocation);
             break;
     }
     $_colorCount = ImageColorsTotal($_result);
     //$this->log->info[] = 'testing image: '. basename($filelocation) . ' colors: '.$_colorCount .
     //" size:[{$imageInfo['width']}x{$imageInfo['height']}]\n";
     if ($this->_maxColors < $_colorCount) {
         $this->_maxColors = $_colorCount;
     }
     if ($_colorCount == 0) {
         $this->_trueColor = true;
     }
     if (!$_result) {
         die("ERROR: Can not open file: {$filelocation}\n");
     }
     return $_result;
 }
Exemplo n.º 3
-1
 function resizeImage($filename, $destination_file, $size = 96, $jpgQuality = 80)
 {
     if (!function_exists('gd_info')) {
         return false;
     }
     $filename = $this->absPath($filename, true);
     $result = false;
     $img = false;
     $img_sz = $this->getimagesize($filename);
     if ($img_sz === false) {
         return false;
     }
     switch ($img_sz[2]) {
         case 1:
             if (function_exists('imagecreatefromgif')) {
                 $img = imagecreatefromgif($filename);
             }
             break;
         case 2:
             if (function_exists('imagecreatefromjpeg')) {
                 $img = imagecreatefromjpeg($filename);
             }
             break;
         case 3:
             if (function_exists('imagecreatefrompng')) {
                 $img = imagecreatefrompng($filename);
             }
             break;
         case 4:
             if (function_exists('imagecreatefromswf')) {
                 $img = imagecreatefromswf($filename);
             }
             break;
     }
     if ($img) {
         $size = (int) $size;
         if ($size < 16) {
             $size = 16;
         }
         $ratio = $img_sz[0] / $img_sz[1];
         $new_width = $size;
         $new_height = (int) ($new_width / $ratio);
         if ($new_width >= $img_sz[0] && $new_height >= $img_sz[1]) {
             return $filename;
         }
         $new_width = min($new_width, $img_sz[0]);
         $new_height = min($new_height, $img_sz[1]);
         $img_resized = null;
         if (function_exists("imagecreatetruecolor")) {
             $img_resized = imagecreatetruecolor($new_width, $new_height);
             imagecolortransparent($img_resized, 0);
         } elseif (function_exists('imagecreate')) {
             $img_resized = imagecreate($new_width, $new_height);
         }
         if ($img_resized) {
             $res = null;
             if (function_exists("imagecopyresampled")) {
                 $res = imagecopyresampled($img_resized, $img, 0, 0, 0, 0, $new_width, $new_height, $img_sz[0], $img_sz[1]);
             } elseif (function_exists("imagecopyresized")) {
                 $res = imagecopyresized($img_resized, $img, 0, 0, 0, 0, $new_width, $new_height, $img_sz[0], $img_sz[1]);
             }
             if ($res) {
                 if (empty($destination_file)) {
                     if (function_exists('imagepng')) {
                         $result = imagepng($img_resized);
                     } elseif (function_exists('imagejpeg')) {
                         $result = imagejpeg($img_resized);
                     } elseif (function_exists('imagegif')) {
                         $result = imagegif($img_resized);
                     }
                 } else {
                     if (function_exists('imagepng')) {
                         $result = imagepng($img_resized, $destination_file);
                     } elseif (function_exists('imagejpeg')) {
                         $result = imagejpeg($img_resized, $destination_file, $jpgQuality);
                     } elseif (function_exists('imagegif')) {
                         $result = imagegif($img_resized, $destination_file);
                     }
                 }
             }
             if ($img_resized) {
                 @imagedestroy($img_resized);
             }
         }
         if ($img) {
             @imagedestroy($img);
         }
         exit;
     }
     if ($result) {
         return $destination_file;
     }
     return false;
 }