本文整理汇总了PHP中Imagine\Image\ImagineInterface::read方法的典型用法代码示例。如果您正苦于以下问题:PHP ImagineInterface::read方法的具体用法?PHP ImagineInterface::read怎么用?PHP ImagineInterface::read使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Imagine\Image\ImagineInterface
的用法示例。
在下文中一共展示了ImagineInterface::read方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: createImageVersions
/**
* @param string $imagePath
* @param string[]|ConfigInterface[] $versionsConfig
* @param string $outputDir
* @param string $imageUniqueName
*
* @return string[]
*/
public function createImageVersions($imagePath, $versionsConfig, $outputDir = null, $imageUniqueName = null)
{
if ($outputDir === null) {
$outputDir = $this->outputDir;
}
if ($imageUniqueName === null) {
$imageUniqueName = $this->getUniqueName($imagePath);
}
$versions = [];
$imageExt = pathinfo($imagePath, PATHINFO_EXTENSION);
foreach ($versionsConfig as $versionName => $versionConfig) {
if (is_string($versionConfig)) {
$config = $this->configParser->parse($versionConfig);
} elseif ($versionConfig instanceof ConfigInterface) {
$config = $versionConfig;
} else {
throw new InvalidConfigException('Config must be a string or implement happyproff\\Kartinki\\Interfaces\\ConfigInterface.');
}
$versionFilename = $imageUniqueName . self::NAME_SEPARATOR . $versionName . '.' . $imageExt;
$image = $this->processor->read(fopen($imagePath, 'r'));
$version = $this->createImageVersion($image, $config);
$version->save($outputDir . '/' . $versionFilename, ['jpeg_quality' => $config->getQuality()]);
unset($version);
$versions[$versionName] = $versionFilename;
}
return $versions;
}
示例2: create
/**
* Creates an image object
*
* @param array|\Imagine\Image\ImageInterface $source
* @throws \InvalidArgumentException On unsupported source type
* @return \Imagine\Image\ImageInterface
*/
public function create($source)
{
if ($source instanceof ImageInterface) {
return $source;
}
if (isset($source['file'])) {
return $this->imagine->open($source['file']);
}
if (isset($source['data'])) {
return $this->imagine->load($source['data']);
}
if (isset($source['resource'])) {
return $this->imagine->read($source['resource']);
}
if (isset($source['width']) && isset($source['height'])) {
return $this->imagine->create(new Box($source['width'], $source['height']));
}
throw new InvalidArgumentException();
}
示例3: createThumbnails
/**
* @param string $imagePath
* @param string[]|PresetInterface[] $presets
* @param string $outputDir
* @param string $imageUniqueId
*
* @return Result
*/
public function createThumbnails($imagePath, $presets, $outputDir = null, $imageUniqueId = null)
{
if (!file_exists($imagePath)) {
throw new FileNotFoundException("File '{$imagePath}' not exists.");
}
if (!is_readable($imagePath)) {
throw new FileIsNotReadableException("File '{$imagePath}' is not readable.");
}
if (is_null($outputDir)) {
$outputDir = $this->outputDir ? $this->outputDir : realpath(dirname($imagePath));
}
if (!is_writable($outputDir)) {
throw new DirectoryIsNotWritableException("Ouput directory '{$outputDir}' is not writable.");
}
if (is_null($imageUniqueId)) {
$imageUniqueId = $this->getUniqueName($imagePath);
} elseif (!is_string($imageUniqueId) && !(is_object($imageUniqueId) && method_exists($imageUniqueId, '__toString'))) {
throw new InvalidArgumentException("{$imageUniqueId} must be a string.");
}
$thumbnails = [];
$imageExtension = pathinfo($imagePath, PATHINFO_EXTENSION);
foreach ($presets as $presetName => $preset) {
if (is_string($preset)) {
$parsedPreset = $this->presetParser->parse($preset);
} elseif ($preset instanceof PresetInterface) {
$parsedPreset = $preset;
} else {
throw new InvalidArgumentException('Preset must be a string or implements kartinki\\Kartinki\\Interfaces\\PresetInterface.');
}
$thumbnailFilename = $imageUniqueId . self::NAME_SEPARATOR . $presetName . '.' . $imageExtension;
$image = $this->processor->read(fopen($imagePath, 'r'));
$thumbnail = $this->createImageThumbnail($image, $parsedPreset);
$thumbnail->save($outputDir . '/' . $thumbnailFilename, ['jpeg_quality' => $parsedPreset->getQuality()]);
unset($thumbnail);
$thumbnails[$presetName] = $thumbnailFilename;
}
$result = new Result($imageUniqueId, $imageExtension, $thumbnails);
return $result;
}
示例4: getImageSize
/**
* Get the size of a Flow Resource object that contains an image file.
*
* @param FlowResource $resource
* @return array width and height as keys
* @throws ImageFileException
*/
public function getImageSize(FlowResource $resource)
{
$cacheIdentifier = $resource->getCacheEntryIdentifier();
$imageSize = $this->imageSizeCache->get($cacheIdentifier);
if ($imageSize !== false) {
return $imageSize;
}
// TODO: Special handling for SVG should be refactored at a later point.
if ($resource->getMediaType() === 'image/svg+xml') {
$imageSize = ['width' => null, 'height' => null];
} else {
try {
$imagineImage = $this->imagineService->read($resource->getStream());
$sizeBox = $imagineImage->getSize();
$imageSize = array('width' => $sizeBox->getWidth(), 'height' => $sizeBox->getHeight());
} catch (\Exception $e) {
throw new ImageFileException(sprintf('The given resource was not an image file your choosen driver can open. The original error was: %s', $e->getMessage()), 1336662898);
}
}
$this->imageSizeCache->set($cacheIdentifier, $imageSize);
return $imageSize;
}