Ejemplo n.º 1
0
 /**
  * Open a file, detect its mime-type and create an image resrource from it.
  * @param  array $file Attributes of file from the $_FILES array
  * @return mixed
  */
 private function openImage($file)
 {
     // If $file isn't an array, we'll turn it into one.
     if (!is_array($file)) {
         $file_dimensions = getimagesize($file);
         $file = array('type' => Inflector::lower($file_dimensions['mime']), 'tmp_name' => $file);
     }
     $mime = $file['type'];
     $file_path = $file['tmp_name'];
     // Confirm that the file actually exists.
     if (!file_exists($file_path)) {
         throw new Exception('Could not find file: ' . $file_path . '. It doesn\'t seem to exist.');
     }
     switch ($mime) {
         case 'image/pjpeg':
             // IE6
         // IE6
         case File::mime('jpg'):
             $img = @imagecreatefromjpeg($file_path);
             break;
         case File::mime('gif'):
             $img = @imagecreatefromgif($file_path);
             break;
         case File::mime('png'):
             $img = @imagecreatefrompng($file_path);
             break;
         default:
             $img = false;
             break;
     }
     return $img;
 }