Пример #1
0
 /**
  * Return the src attribute to put into the img tag
  *
  * @see ImageInterface::src
  * @param string $size Size to use
  */
 public function src($size)
 {
     global $globals;
     $order = ImageSizesSet::sizeToOrder($size);
     while ($order >= 0) {
         if (file_exists($globals->spoolroot . '/htdocs/static/' . $order . '/' . $this->path())) {
             return 'static/' . $order . '/' . $this->path();
         }
         $order--;
     }
     throw new Exception('No such image');
 }
Пример #2
0
 protected static function loadConf()
 {
     global $globals;
     if (self::$sizes == null) {
         self::$sizes = array();
         self::$order = json_decode($globals->sizes->order);
         foreach (self::$order as $size) {
             self::$sizes[$size] = ImageSize::fromExport(json_decode($globals->sizes->{$size}));
         }
     }
 }
Пример #3
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);
     }
 }