示例#1
0
 public function createImage($imageBytes, $imageDescription, $tag, $location)
 {
     $imageFile = new Upload($imageBytes);
     if ($imageFile->uploaded) {
         $extension = exif_imagetype($imageFile->file_src_pathname);
         // Constant 2 = JPEG
         if ($extension != 2) {
             throw new InvalidImageExtensionException();
         }
         $sha1 = sha1_file($imageFile->file_src_pathname);
         if ($this->imageExists($sha1)) {
             throw new ImageAlreadyExistsException();
         }
         $fileSize = filesize($imageFile->file_src_pathname);
         $imageModel = new ImageModel($this->db);
         $image = $imageModel->insert($sha1, $fileSize, $imageDescription, $tag, $location);
         $imageName = $image->getId() . "_" . $sha1;
         $this->saveOriginal($imageFile, $imageName);
         $this->saveThumbnailSquare($imageFile, $imageName);
         $this->saveThumbnailEmbedded($imageFile, $imageName);
         $this->saveWebDefault($imageFile, $imageName);
         $this->saveThumbnailAndroid($imageFile, $imageName);
         return $image;
     }
 }