This class provides methods for setting and returning the component configuration.
Inheritance: use trait Webiny\Component\StdLib\ComponentTrait
Beispiel #1
0
 /**
  * Returns an instance of ImageLoaderInterface.
  *
  * @return null|ImageLoaderInterface
  */
 private static function getLoader()
 {
     if (self::isNull(self::$loader)) {
         self::$loader = Loader::getImageLoader(Image::getConfig());
     }
     return self::$loader;
 }
Beispiel #2
0
 public function provideImage()
 {
     Image::setConfig(realpath(__DIR__ . '/../../' . self::CONFIG));
     // build File mock
     $file = $this->getMockBuilder('\\Webiny\\Component\\Storage\\File\\File')->disableOriginalConstructor()->setMethods(['getAbsolutePath', 'getKey'])->getMock();
     // getAbsolutePath mock
     $file->expects($this->any())->method('getAbsolutePath')->will($this->returnValue(__DIR__ . '/../../image.gif'));
     // getKey mock
     $file->expects($this->once())->method('getKey')->will($this->returnValue(__DIR__ . '/../../image.gif'));
     $image = ImageLoader::open($file);
     return [[$image]];
 }
Beispiel #3
0
 /**
  * Saves the image in the defined storage.
  *
  * @param File  $file    Where to save the image.
  * @param array $options An array of options. Possible keys are [quality, filters].
  *
  * @return bool True if image is save successfully, otherwise false.
  *
  * @throws \Exception|ImageException
  */
 public function save(File $file = null, $options = [])
 {
     if ($this->isNull($file)) {
         if ($this->isNull($this->destination)) {
             throw new ImageException('Unable to save the image. Destination storage is not defined.');
         }
         $file = $this->destination;
     }
     // extract the type
     try {
         $format = $this->str($file->getKey())->explode('.')->last()->caseLower()->val();
         $this->setFormat($format);
     } catch (ImageException $e) {
         throw $e;
     }
     // check quality parameter
     $options['quality'] = isset($options['Quality']) ? $options['Quality'] : Image::getConfig()->get('Quality', 90);
     return $file->setContents($this->getBinary($options));
 }
Beispiel #4
0
 public function setUp()
 {
     Image::setConfig(realpath(__DIR__ . self::CONFIG));
 }
Beispiel #5
0
 public function testConfigContent()
 {
     $this->assertSame(90, Image::getConfig()->Quality);
     $this->assertSame('gd', Image::getConfig()->Library);
     $this->assertSame('\\Webiny\\Component\\Image\\Bridge\\Imagine\\Imagine', Image::getConfig()->Bridge);
 }
Beispiel #6
0
 /**
  * Get the name of bridge library which will be used as the driver.
  *
  * @return string
  */
 private static function getLibrary()
 {
     return Image::getConfig()->get('Bridge', self::$library);
 }