public function __invoke(ServerRequestInterface $request, ResponseInterface $response, callable $next = null) { parent::__invoke($request, $response, $next); if (!$this->isSupportedResponse($response)) { return $next($request, $response); } $crop = $this->resourceDO->getCrop(); if ($this->resourceDO->getDimension() && $crop) { $path = $this->resourceDO->getFilePath(); // (POST) Resource just created or re-created if ($this->resourceDO->isNew() || $this->resourceDO->isRecreate()) { /** * Explanation: If it's just an artifact that is left from the previous file after re-creation * than you need to remove it exact in recreation moment * @see \Staticus\Resources\Middlewares\Image\SaveImageMiddlewareAbstract::afterSave */ // Some of previous middlewares already created this file size if ($this->filesystem->has($path)) { $this->cropImage($path, $path, $crop); } else { $modelResourceDO = $this->getResourceWithoutSizes(); $this->cropImage($modelResourceDO->getFilePath(), $path, $crop); } // (GET) Resource should be exist, just check if this size wasn't created before } else { if (!$this->filesystem->has($path)) { $modelResourceDO = $this->getResourceWithoutSizes(); $this->cropImage($modelResourceDO->getFilePath(), $path, $crop); } } } return $next($request, $response); }
public function __invoke(ServerRequestInterface $request, ResponseInterface $response, callable $next = null) { parent::__invoke($request, $response, $next); if (!$this->isSupportedResponse($response)) { return $next($request, $response); } if ($this->mustBeStripped()) { $this->stripImage($this->resourceDO->getFilePath()); } return $next($request, $response); }
public function __invoke(ServerRequestInterface $request, ResponseInterface $response, callable $next = null) { parent::__invoke($request, $response, $next); if (!$this->isSupportedResponse($response)) { return $next($request, $response); } if ($this->isAllowed()) { $interlacing = $this->config->get('staticus.images.compress.interlace', false); $quality = $this->config->get('staticus.images.compress.quality', false); $maxWidth = $this->config->get('staticus.images.compress.maxWidth', false); $maxHeight = $this->config->get('staticus.images.compress.maxHeight', false); $this->compress($this->resourceDO->getFilePath(), $interlacing, $quality, $maxWidth, $maxHeight); } return $next($request, $response); }