/** * Constructs a new simple sized path service * * @param \Symfony\Component\HttpKernel\KernelInterface $kernel * @param \Symfony\Component\HttpFoundation\Request $request * @param string $relativePath the relative path from the web dir * @param string $imageType the image type, on of the ImageHandler::IMAGE_TYPE_* constants * @param string|null $hashPrefix prefix for file name hashing. No hashing is applied to the filename, if $hashPrefix is null * * @throws \InvalidArgumentException */ public function __construct(KernelInterface $kernel, Request $request, $relativePath, $imageType, $hashPrefix = null) { parent::__construct($kernel, $request); if (!ImageHandler::isSupportedImageType($imageType)) { throw new \InvalidArgumentException("Image type not supported: {$imageType}. Supported image types are: " . implode(", ", ImageHandler::getSupportedImageTypes())); } $this->imageType = $imageType; $this->hashPrefix = $hashPrefix; $this->relativePath = trim($relativePath, "/"); }
/** * Modifies the image according to the given dimension data * * @param ImageHandler $image * @param array $imageData */ protected function modifyImage(ImageHandler $image, array $imageData) { if (isset($imageData["maxWidth"], $imageData["maxHeight"])) { $image->scaleToMaximumDimensions($imageData["maxWidth"], $imageData["maxHeight"]); } else { if (isset($imageData["maxWidth"])) { $image->scaleToWidth($imageData["maxWidth"]); } else { if (isset($imageData["maxHeight"])) { $image->scaleToHeight($imageData["maxHeight"]); } else { if (isset($imageData["cropWidth"], $imageData["cropHeight"])) { $image->cropToSize($imageData["cropWidth"], $imageData["cropHeight"]); } } } } }