/**
  * Resizes an image
  *
  * @return Response
  *
  * @throws EntityNotFoundException Requested image does not exist
  */
 public function resizeAction()
 {
     $request = $this->requestStack->getCurrentRequest();
     $id = $request->get('id');
     /**
      * We retrieve image given its id
      */
     $image = $this->imageRepository->find($id);
     if (!$image instanceof ImageInterface) {
         throw new EntityNotFoundException($this->imageRepository->getClassName());
     }
     $response = new Response();
     $height = $request->get('height');
     $width = $request->get('width');
     $type = $request->get('type');
     $response->setEtag($this->imageEtagTransformer->transform($image, $height, $width, $type))->setLastModified($image->getUpdatedAt())->setStatusCode(304)->setPublic();
     /**
      * If the object has not been modified, we return the response.
      * Symfony will automatically put a 304 status in the response
      * in that case
      */
     if ($response->isNotModified($request)) {
         return $response;
     }
     $image = $this->imageManager->resize($image, $height, $width, $type);
     $imageData = $image->getContent();
     $response->setStatusCode(200)->setMaxAge($this->maxAge)->setSharedMaxAge($this->sharedMaxAge)->setContent($imageData);
     $response->headers->add(array('Content-Type' => $image->getContentType()));
     return $response;
 }
 /**
  * Create new response given a request and an image.
  *
  * Fill some data to this response given some Image properties and check if
  * created Response has changed.
  *
  * @param Request        $request Request
  * @param ImageInterface $image   Image
  *
  * @return Response Created response
  */
 private function buildResponseFromImage(Request $request, ImageInterface $image)
 {
     $response = new Response();
     $height = $request->get('height');
     $width = $request->get('width');
     $type = $request->get('type');
     $response->setEtag($this->imageEtagTransformer->transform($image, $height, $width, $type))->setLastModified($image->getUpdatedAt())->setPublic();
     /**
      * If the object has not been modified, we return the response.
      * Symfony will automatically put a 304 status in the response
      * in that case
      */
     if ($response->isNotModified($request)) {
         return $response->setStatusCode(304);
     }
     $image = $this->imageManager->resize($image, $height, $width, $type);
     $imageData = $image->getContent();
     $response->setStatusCode(200)->setMaxAge($this->maxAge)->setSharedMaxAge($this->sharedMaxAge)->setContent($imageData);
     $response->headers->add(['Content-Type' => $image->getContentType()]);
     return $response;
 }