Ejemplo n.º 1
0
 /**
  * Build the image from a FrankizUpload instance, stores it into the DB
  *
  * @param $fu      Instance of FrankizUpload
  * @param $rm      Should the temporary file be removed after ? (Default: yes)
  */
 public function image(FrankizUpload $fu, $rm = true)
 {
     $infos = getimagesize($fu->path());
     $this->mime = $infos['mime'];
     $types = array(IMAGETYPE_GIF, IMAGETYPE_JPEG, IMAGETYPE_PNG);
     if (!in_array($infos[2], $types)) {
         throw new ImageFormatException();
     }
     $this->x = $infos[0];
     $this->y = $infos[1];
     if ($this->x > ImageSize::MAX_WIDTH() || $this->y > ImageSize::MAX_HEIGHT()) {
         $e = new ImageSizeException('The picture is to big: (' . $this->x . 'x' . $this->y . ') > (' . ImageSize::MAX_WIDTH() . 'x' . ImageSize::MAX_HEIGHT() . ')');
         $e->size(new ImageSize($this->x, $this->y));
         $e->allowed(ImageSize::MAX());
         throw $e;
     }
     $this->images = ImageSizesSet::resize(file_get_contents($fu->path()));
     if ($rm) {
         $fu->rm();
     }
     foreach ($this->images as $size => $image) {
         $size_order = ImageSizesSet::sizeToOrder($size);
         XDB::execute('INSERT INTO  images_sizes
                               SET  iid = {?}, size = {?}, mime = {?}, x = {?}, y = {?}, data = {?}
           ON DUPLICATE KEY UPDATE  mime = {?}, x = {?}, y = {?}, data = {?}', $this->id(), $size_order, $image->mime, $image->x, $image->y, $image->data, $image->mime, $image->x, $image->y, $image->data);
     }
 }