Returns the content.
public getContent ( array $metadata = [] ) : string | ||
$metadata | array | optional metadata which should be set when read |
return | string |
/** * {@inheritdoc} */ public function resize(MediaInterface $media, File $in, File $out, $format, array $settings) { if (!isset($settings['width'])) { throw new \RuntimeException(sprintf('Width parameter is missing in context "%s" for provider "%s"', $media->getContext(), $media->getProviderName())); } $image = $this->adapter->load($in->getContent()); $size = $media->getBox(); 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, $this->metadata->get($media, $out->getName())); }
/** * {@inheritdoc} */ public function resize(MediaInterface $media, File $in, File $out, $format, array $settings) { if (!isset($settings['width'])) { throw new \RuntimeException(sprintf('Width parameter is missing in context "%s" for provider "%s"', $media->getContext(), $media->getProviderName())); } $image = $this->adapter->load($in->getContent()); $content = $image->thumbnail($this->getBox($media, $settings), $this->mode)->get($format, array('quality' => $settings['quality'])); $out->setContent($content, $this->metadata->get($media, $out->getName())); }
/** * @inheritdoc * @throws \RuntimeException */ public function download($id, FileInterface $output) { $source = new GFile($id, $this->filesystem); ErrorHandler::start(); $flag = file_put_contents($output->getPath(), $source->getContent()); ErrorHandler::stop(true); if ($flag === false) { throw new \RuntimeException("Could not download file ({$id})"); } }
/** * @param \Sonata\MediaBundle\Model\MediaInterface $media * @param \Gaufrette\File $in * @param \Gaufrette\File $out * @param string $format * @param array $settings * @return void */ public function resize(MediaInterface $media, File $in, File $out, $format, $settings) { if (!isset($settings['width'])) { throw new \RuntimeException(sprintf('Width parameter is missing in context "%s" for provider "%s"', $media->getContext(), $media->getProviderClass())); } $image = $this->getAdapter()->load($in->getContent()); if ($settings['height'] == null) { $size = $image->getSize(); $settings['height'] = (int) ($settings['width'] * $size->getHeight() / $size->getWidth()); } $content = $image->thumbnail(new Box($settings['width'], $settings['height']), $this->getMode())->get($format); $out->setContent($content); }
/** * @param File $file */ public function __construct(File $file) { $this->domains = Utilities::parseLines($file->getContent()); }
public function getContent() { return $this->file->getContent(); }
private function parseFile(File $file) { $parser = new Parser(new Lexer()); return $parser->parse($file->getContent()); }
/** * {@inheritdoc} */ public function resize(MediaInterface $media, File $in, File $out, $format, array $settings) { $image = $this->adapter->load($in->getContent()); $size = $image->getSize(); $originalRatio = $size->getWidth() / $size->getHeight(); if ($settings['width'] === null && $settings['height'] === null) { $settings['width'] = $size->getWidth(); $settings['height'] = $size->getHeight(); } if (!$settings['width']) { $settings['width'] = $size->getWidth(); } if (!$settings['height']) { $settings['height'] = $settings['width'] * $originalRatio; } // Scale Image up if too small if ($size->getHeight() > $size->getWidth()) { if ($settings['height'] > $size->getHeight()) { $image->resize(new Box($settings['height'] * $originalRatio, $settings['height'])); } } else { if ($settings['width'] > $size->getWidth()) { $image->resize(new Box($settings['width'], $settings['width'] / $originalRatio)); } } // Re calculate size and aspect ratio $size = $image->getSize(); $originalRatio = $size->getWidth() / $size->getHeight(); // Resize and on center if ($size->getHeight() > $size->getWidth()) { $thRatio = $settings['width'] / $settings['height']; $higher = $size->getHeight(); $lower = $size->getWidth(); $newWidth = $thRatio * $higher; $newHeight = $lower / $thRatio; if ($newWidth < $settings['width']) { $newWidth = $settings['width']; } if ($newHeight < $settings['height']) { $newHeight = $settings['height']; } $crop = ($higher - $newHeight) / 2; if ($crop > 0) { $point = new Point(0, $crop); $image->crop($point, new Box($lower, $newHeight)); } else { $cropHigher = -($crop * $thRatio); $point = new Point($cropHigher, 0); $image->crop($point, new Box($newWidth, $higher)); } } else { $thRatio = $settings['width'] / $settings['height']; $higher = $size->getWidth(); $lower = $size->getHeight(); $newWidth = $thRatio * $lower; $newHeight = $higher / $thRatio; if ($newWidth < $settings['width']) { $newWidth = $settings['width']; } if ($newHeight < $settings['height']) { $newHeight = $settings['height']; } $crop = ($higher - $newWidth) / 2; if ($crop > 0) { $point = new Point($crop, 0); $image->crop($point, new Box($newWidth, $lower)); } else { $cropLower = -($crop / $thRatio); $point = new Point(0, $cropLower); $image->crop($point, new Box($higher, $newHeight)); } } // Generate thumbnail $content = $image->thumbnail(new Box($settings['width'], $settings['height']), $this->mode)->get($format, array('quality' => $settings['quality'])); $out->setContent($content); }