示例#1
0
 /**
  * Parse, filter and sort options.
  *
  * @param unknown_type $options
  * @throws Exception
  */
 protected function parse_params($params)
 {
     global $core;
     #
     # handle the 'version' parameter
     #
     if (isset($params['v'])) {
         $params['version'] = $params['v'];
     }
     if (isset($params['version'])) {
         $version_name = $params['version'];
         $versions = $core->thumbnailer_versions;
         $version = $versions[$version_name];
         $params += $version->to_array(Version::ARRAY_FILTER);
         unset($params['version']);
     }
     #
     $params = Version::normalize($params);
     if (empty($params['background'])) {
         $params['background'] = 'transparent';
     }
     if ($params['format'] == 'jpeg' && $params['background'] == 'transparent') {
         $params['background'] = 'white';
     }
     Image::assert_sizes($params['method'], $params['width'], $params['height']);
     return $params;
 }
 private function dispatch_value($value, $attribute)
 {
     $version = new Version($value);
     $options = $version->to_array();
     if (!empty($value['lightbox'])) {
         $options['lightbox'] = true;
     }
     if ($options['background'] == 'transparent') {
         $options['background'] = '';
     }
     foreach ($options as $name => $v) {
         if (empty($this->elements[$name])) {
             continue;
         }
         $element = $this->elements[$name];
         if ($element['type'] == 'checkbox' && $attribute == 'value') {
             $element['checked'] = $v;
         } else {
             $element[$attribute] = $v;
         }
     }
 }
示例#3
0
 /**
  * Returns the thumbnail URL.
  *
  * @return string The thumbnail URL.
  */
 public function volatile_get_url()
 {
     global $core;
     $src = $this->src;
     $options = Version::filter($this->options);
     $version_name = $this->version_name;
     $url = '/api/';
     $w = $this->w;
     $h = $this->h;
     $method = $this->method;
     if (is_string($src)) {
         $url .= 'thumbnail';
         $options['src'] = $src;
         $options['version'] = $version_name;
         if ($w || $h) {
             $url .= '/';
             if ($w && $h) {
                 $url .= $w . 'x' . $h;
             } else {
                 if ($w) {
                     $url .= $w;
                     $method = 'fixed-width';
                 } else {
                     if ($h) {
                         $url .= 'x' . $h;
                         $method = 'fixed-height';
                     }
                 }
             }
             unset($options['width']);
             unset($options['height']);
             if ($method) {
                 $url .= '/' . $method;
                 unset($options['method']);
             }
         }
     } else {
         $url .= (empty($src->constructor) ? $src->model_id : $src->constructor) . '/' . $src->nid;
         if ($version_name) {
             $url .= '/thumbnails/' . $version_name;
         } else {
             if ($w || $h) {
                 $url .= '/';
                 if ($w && $h) {
                     $url .= $w . 'x' . $h;
                 } else {
                     if ($w) {
                         $url .= $w;
                         $method = 'fixed-width';
                     } else {
                         if ($h) {
                             $url .= 'x' . $h;
                             $method = 'fixed-height';
                         }
                     }
                 }
                 unset($options['width']);
                 unset($options['height']);
                 if ($method) {
                     $url .= '/' . $method;
                     unset($options['method']);
                 }
             } else {
                 $url .= '/thumbnail';
             }
         }
     }
     if ($options) {
         $url .= '?' . http_build_query(Version::shorten($options));
     }
     return $url;
 }