コード例 #1
0
ファイル: Image.php プロジェクト: maddoger/yii2-imagecache
 /**
  * Show image to browser
  * @param $format
  * @param array $options
  * @return $this
  */
 public function get($format, $options = [])
 {
     if ($this->image) {
         return $this->image->get($format, $options);
     }
     return null;
 }
コード例 #2
0
 /**
  * {@inheritDoc}
  *
  * @return AssetInterface|ImageInterface
  */
 public function apply(ImageInterface $image)
 {
     $asset = new StringAsset($image->get('png'));
     $asset->load();
     try {
         $this->filter->filterDump($asset);
     } catch (FilterException $e) {
         // FilterException is thrown when "optipng" utility was not found.
         // This should never happen on production environment; maybe we should enforce it?
     }
     // TODO: workaround hackish way of applying optipng and other compression filters.
     // Without that we're loosing some optimizations by running content through image library functions!
     return new ImageAssetWrapper($asset);
     //        return $this->imagine->load($asset->getContent());
 }
コード例 #3
0
 public function it_can_output_the_result(File $file, ImageInterface $image)
 {
     $result = 'resultingimagestring';
     $file->getMimeType()->willReturn(MimeTypeValue::get('image/jpg'));
     $image->get('jpeg')->willReturn($result);
     $this->output($file, $image)->shouldReturn($result);
 }
コード例 #4
0
 /**
  * @param  ImageInterface $image
  * @return string
  **/
 private function getBinaryStringForImage(ImageInterface $image)
 {
     return $image->get($this->definition->getImageFormat(), $this->definition->getImageOptions());
 }
コード例 #5
0
 public function output(File $file, ImageInterface $image) : string
 {
     return $image->get($this->determineImageFormat($file));
 }
コード例 #6
0
ファイル: Manager.php プロジェクト: pscheit/psc-cms-image
 /**
  * Erstellt ein neues Bild und fügt es dem Manager hinzu
  *
  * Gibt das Bild um $imagineImage zurück
  * @return Image
  */
 public function store(ImagineImage $imagineImage, $label = NULL, $flags = 0x0)
 {
     $hash = sha1($imagineImage->get('png'));
     if (($flags & self::IF_NOT_EXISTS) === self::IF_NOT_EXISTS) {
         try {
             $image = $this->load($hash);
             $file = $image->getSourceFile();
             if (!$file->exists()) {
                 $file->getDirectory()->create();
                 // das ist eigentlich SEHR unerwartet, weil dann die db nicht mit dem filesystem in sync ist:
                 $image->setImagineImage($imagineImage);
                 $imagineImage->save((string) $file);
                 if ($file->getSize() <= 0) {
                     throw new ProcessingException('Fehler beim (NEU-)Speichern von Bild: ' . $file . "\n" . "Memory Usage: " . Code::getMemoryUsage() . "\n" . 'Datei wurde von Imagine nicht geschrieben');
                 }
                 $this->em->persist($image);
             }
             return $image;
         } catch (\Psc\Image\NotFoundException $e) {
         }
     }
     $image = $this->newInstance();
     $image->setLabel(trim($label));
     $image->setImagineImage($imagineImage);
     /* filename */
     // wir speichern dumpf immer in png ab
     $file = $this->generateFile($hash, 'png');
     $image->setSourceFile($file);
     // damits schon gecached ist
     $rel = clone $file;
     $rel->makeRelativeTo($this->directory);
     $image->setSourcePath((string) $rel);
     /* binärdaten Physikalisch speichern */
     $image->getImagineImage()->save((string) $file);
     if ($file->getSize() <= 0) {
         throw new ProcessingException('Fehler beim Speichern von Bild: ' . $file . "\n" . "Memory Usage: " . Code::getMemoryUsage() . "\n" . 'Datei wurde von Imagine nicht geschrieben');
     }
     /* binärdaten hashen */
     $image->setHash($hash);
     // sha1_file((string) $file)
     /* Datenbank speichern */
     $this->em->persist($image);
     $this->doAttach($image);
     return $image;
 }