Пример #1
0
 /**
  * Initializes the component by validating [[apiKey]].
  *
  * @throws InvalidConfigException if [[apiKey]] is not set.
  * @throws UnauthorizedHttpException if [[apiKey]] could not be validated.
  */
 public function init()
 {
     if (!$this->apiKey) {
         throw new InvalidConfigException("The property 'apiKey' must be in set in " . get_class($this) . ".");
     }
     try {
         Tinify\setKey($this->apiKey);
         Tinify\validate();
     } catch (\Tinify\Exception $e) {
         throw new UnauthorizedHttpException("The specified apiKey '{$this->apiKey}' could not be validated.");
     }
 }
Пример #2
0
 public function update()
 {
     $this->setStatus(self::UNKNOWN);
     if ($this->config->apply()) {
         try {
             Tinify\validate();
             $this->setStatus(self::SUCCESS);
             $this->setLastError(null);
         } catch (\Exception $err) {
             $this->setStatus(self::FAILURE);
             $this->setLastError($err->getMessage());
         }
         $this->setCompressionCount(Tinify\getCompressionCount());
     }
     $this->save();
 }
Пример #3
0
 /**
  * Runs TinyPNG optimization
  *
  * @param $file
  * @param $transform
  */
 public function runTinyPng($file)
 {
     try {
         \Tinify\setKey($this->getSetting('tinyPngApiKey'));
         \Tinify\validate();
         \Tinify\fromFile($file)->toFile($file);
     } catch (\Tinify\Exception $e) {
         ImagerPlugin::log("Could not validate connection to TinyPNG, image was not optimized.", LogLevel::Error);
     }
 }