/** * {@inheritdoc} */ public function resize(Media $media, File $in, File $out, $format, array $settings) { if (!array_key_exists('quality', $settings)) { $settings['quality'] = 100; } if (!isset($settings['width'])) { throw new \RuntimeException(sprintf('Width parameter is missing in context "%s" for provider "%s"', $media->getContext(), $media->getName())); } $image = $this->adapter->load($in->getContent()); $size = $media->getBox(); var_dump($size); if (null != $settings['height']) { if ($size->getHeight() > $size->getWidth()) { $higher = $size->getHeight(); $lower = $size->getWidth(); } else { $higher = $size->getWidth(); $lower = $size->getHeight(); } $crop = $higher - $lower; if ($crop > 0) { $point = $higher == $size->getHeight() ? new Point(0, 0) : new Point($crop / 2, 0); $image->crop($point, new Box($lower, $lower)); $size = $image->getSize(); } } $settings['height'] = (int) ($settings['width'] * $size->getHeight() / $size->getWidth()); if ($settings['height'] < $size->getHeight() && $settings['width'] < $size->getWidth()) { $content = $image->thumbnail(new Box($settings['width'], $settings['height']), $this->mode)->get($format, array('quality' => $settings['quality'])); } else { $content = $image->get($format, array('quality' => $settings['quality'])); } $out->setContent($content); }
/** * {@inheritdoc} */ public function getBox(Media $media, array $settings) { $size = $media->getBox(); if ($settings['width'] == null && $settings['height'] == null) { throw new \RuntimeException(sprintf('Width/Height parameter is missing in context "%s" for provider "%s". Please add at least one parameter.', $media->getContext(), $media->getProviderName())); } if ($settings['height'] == null) { $settings['height'] = (int) ($settings['width'] * $size->getHeight() / $size->getWidth()); } if ($settings['width'] == null) { $settings['width'] = (int) ($settings['height'] * $size->getWidth() / $size->getHeight()); } return $this->computeBox($media, $settings); }