/** * Handle request to convert it to a Response object. */ public function handle() { try { if (!$this->request->query->has('image')) { throw new FileNotFoundException("No valid image path found in URI", 1); } $nativePath = $this->configuration->getImagesPath() . '/' . $this->request->query->get('image'); $this->nativeImage = new File($nativePath); $this->parseQuality(); if ($this->configuration->hasCaching()) { $cache = new FileCache($this->request, $this->nativeImage, $this->configuration->getCachePath(), $this->logger, $this->quality, $this->configuration->getTtl(), $this->configuration->getGcProbability(), $this->configuration->getUseFileChecksum()); $cache->setDispatcher($this->dispatcher); /** @var Response response */ $this->response = $cache->getResponse(function (InterventionRequest $interventionRequest) { return $interventionRequest->processImage(); }, $this); } else { $this->processImage(); $this->response = new Response((string) $this->image->encode(null, $this->quality), Response::HTTP_OK, ['Content-Type' => $this->image->mime(), 'Content-Disposition' => 'filename="' . $this->nativeImage->getFilename() . '"', 'X-Generator-First-Render' => true]); $this->response->setLastModified(new \DateTime('now')); } } catch (FileNotFoundException $e) { $this->response = $this->getNotFoundResponse($e->getMessage()); } catch (\RuntimeException $e) { $this->response = $this->getBadRequestResponse($e->getMessage()); } }