示例#1
0
 /**
  * Creates a new version of a specific image.
  * @param integer $id the image id.
  * @param string $version the image version.
  * @return ThumbBase
  * @throws CException if creating the image version fails.
  */
 public function createVersion($id, $version)
 {
     if (isset($this->versions[$version])) {
         $image = $this->load($id);
         if ($image != null) {
             $fileName = $this->resolveFileName($image);
             $thumb = self::thumbFactory($this->resolveImagePath($image) . $fileName);
             $options = ImageOptions::create($this->versions[$version]);
             $thumb->applyOptions($options);
             $path = $this->resolveImageVersionPath($image, $version);
             if (!file_exists($path) && !$this->createDirectory($path)) {
                 throw new CException(__CLASS__ . ': Failed to create version! Directory could not be created.');
             }
             $path .= $fileName;
             return $thumb->save($path);
         } else {
             throw new CException(__CLASS__ . ': Failed to create version! Image could not be found.');
         }
     } else {
         throw new CException(__CLASS__ . ': Failed to create version! Version is unknown.');
     }
 }
 /**
  * @param ImageOptions|null $options
  *
  * @return string
  *
  * @api
  */
 public function getUrl(ImageOptions $options = null)
 {
     $query = $options !== null ? '?' . $options->getQueryString() : '';
     return parent::getUrl() . $query;
 }