/** * @inheritDoc ITask::runStep() * * @param int $step * * @return bool */ public function runStep($step) { if (is_array($this->_paths)) { $path = $this->_paths[$step]; } else { $path = $this->_paths; } Tinify\setKey(craft()->imager->getSetting('tinyPngApiKey')); Tinify\fromFile($path)->toFile($path); return true; }
/** * 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); } }
/** * Resizes and compresses the specified image. * * @param string $src the image source path. * @param string $dst the image destination path after being resized. If not set $src * will be overwritten. * @param array $options options used when resizing. Options array must be formatted like so: * ~~~php * [ * 'method' => 'fit', * 'width' => 150, * 'height' => 100, * ] * ~~~ * * Available methods are: * - scale * - fit * - cover * * See [TinyPng docs](https://tinypng.com/developers/reference/php) for information about each method. */ public function resize($src, $dst, $options) { $dst = $dst ?: $src; $source = Tinify\fromFile($src); $resized = $source->resize($options); $resized->toFile($dst); }