/** * Processes the resize and executes it if not already cached. * * @param ImageInterface $image * @param ResizeConfigurationInterface $config * @param ResizeOptionsInterface $options * * @return ImageInterface */ private function processResize(ImageInterface $image, ResizeConfigurationInterface $config, ResizeOptionsInterface $options) { $coordinates = $this->calculator->calculate($config, $image->getDimensions(), $image->getImportantPart()); // Skip resizing if it would have no effect if ($coordinates->isEqualTo($image->getDimensions()->getSize()) && !$image->getDimensions()->isRelative()) { return $this->createImage($image, $image->getPath()); } $cachePath = $this->cacheDir . '/' . $this->createCachePath($image->getPath(), $coordinates); if ($this->filesystem->exists($cachePath) && !$options->getBypassCache()) { return $this->createImage($image, $cachePath); } return $this->executeResize($image, $coordinates, $cachePath, $options); }
/** * {@inheritdoc} */ public function getImportantPartFromLegacyMode(ImageInterface $image, $mode) { if (1 !== substr_count($mode, '_')) { throw new \InvalidArgumentException(sprintf('"%s" is not a legacy resize mode', $mode)); } $importantPart = [0, 0, $image->getDimensions()->getSize()->getWidth(), $image->getDimensions()->getSize()->getHeight()]; list($modeX, $modeY) = explode('_', $mode); if ('left' === $modeX) { $importantPart[2] = 1; } elseif ('right' === $modeX) { $importantPart[0] = $importantPart[2] - 1; $importantPart[2] = 1; } if ('top' === $modeY) { $importantPart[3] = 1; } elseif ('bottom' === $modeY) { $importantPart[1] = $importantPart[3] - 1; $importantPart[3] = 1; } return new ImportantPart(new Point($importantPart[0], $importantPart[1]), new Box($importantPart[2], $importantPart[3])); }