mirror of
https://github.com/getgrav/grav.git
synced 2026-06-26 00:20:41 +02:00
Fixed error when resizing image
This commit is contained in:
@@ -49,6 +49,9 @@ class LocalMediaFactory implements MediaFactoryInterface
|
||||
public function readFile(string $type, string $path): string
|
||||
{
|
||||
$filepath = GRAV_WEBROOT . '/' . $path;
|
||||
if (!is_file($filepath)) {
|
||||
throw new RuntimeException(sprintf("Reading media file failed: File '%s' not found", $path));
|
||||
}
|
||||
|
||||
error_clear_last();
|
||||
$contents = @file_get_contents($filepath);
|
||||
@@ -67,6 +70,9 @@ class LocalMediaFactory implements MediaFactoryInterface
|
||||
public function readStream(string $type, string $path)
|
||||
{
|
||||
$filepath = GRAV_WEBROOT . '/' . $path;
|
||||
if (!is_file($filepath)) {
|
||||
throw new RuntimeException(sprintf("Reading media file failed: File '%s' not found", $path));
|
||||
}
|
||||
|
||||
error_clear_last();
|
||||
$contents = @fopen($filepath, 'rb');
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
namespace Grav\Common\Media\Traits;
|
||||
|
||||
use BadFunctionCallException;
|
||||
use Exception;
|
||||
use Grav\Common\Debugger;
|
||||
use Grav\Common\Grav;
|
||||
use Grav\Common\Media\Interfaces\ImageMediaInterface;
|
||||
@@ -81,17 +82,25 @@ trait ImageMediaTrait
|
||||
|
||||
$mediaFactory = Grav::instance()['media_factory'];
|
||||
|
||||
$fileData = $mediaFactory->readFile($mediaUri);
|
||||
$adapter = GdAdapter::createFromString($fileData);
|
||||
try {
|
||||
$fileData = $mediaFactory->readFile($mediaUri);
|
||||
$adapter = GdAdapter::createFromString($fileData);
|
||||
|
||||
$image = Image::createFromArray($data);
|
||||
$image = Image::createFromArray($data);
|
||||
|
||||
$image->setAdapter($adapter);
|
||||
$filepath = $image->save($filepath, $format, $quality);
|
||||
$image->freeAdapter();
|
||||
$image->setAdapter($adapter);
|
||||
$filepath = $image->save($filepath, $format, $quality);
|
||||
$image->freeAdapter();
|
||||
|
||||
$time = filemtime($filepath);
|
||||
$size = filesize($filepath);
|
||||
$time = filemtime($filepath);
|
||||
$size = filesize($filepath);
|
||||
} catch (Exception $e) {
|
||||
/** @var Debugger $debugger */
|
||||
$debugger = Grav::instance()['debugger'];
|
||||
$debugger->addException($e);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
return [$filepath, $mime, $time, $size];
|
||||
}
|
||||
@@ -665,11 +674,16 @@ trait ImageMediaTrait
|
||||
$format = $extension;
|
||||
}
|
||||
|
||||
|
||||
$image = $this->image;
|
||||
|
||||
$mediaUri = $this->getMedia()->getMediaUri($this->filename);
|
||||
if (null === $mediaUri) {
|
||||
$mediaUri = 'media-local://' . str_replace('GRAV_WEBROOT', '', $image->getFilepath());
|
||||
}
|
||||
|
||||
$image->extra['format'] = $format;
|
||||
$image->extra['quality'] = $quality;
|
||||
$image->extra['media-uri'] = $this->getMedia()->getMediaUri($this->filename);
|
||||
$image->extra['media-uri'] = $mediaUri;
|
||||
$image->extra['mime'] = $this->mime;
|
||||
|
||||
$data = $image->jsonSerialize();
|
||||
|
||||
@@ -114,14 +114,11 @@ abstract class AbstractMedia implements ExportInterface, MediaCollectionInterfac
|
||||
|
||||
/**
|
||||
* @param string $filename
|
||||
* @return string
|
||||
* @return string|null
|
||||
*/
|
||||
public function getMediaUri(string $filename): string
|
||||
public function getMediaUri(string $filename): ?string
|
||||
{
|
||||
$schema = 'media-' . str_replace('_', '-', $this->getName());
|
||||
$path = $this->getRealPath($filename);
|
||||
|
||||
return "{$schema}://{$path}";
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -79,6 +79,11 @@ class Image implements ImageOperationsInterface, JsonSerializable
|
||||
$this->orientation = isset($info['exif']['Orientation']) ? (int)$info['exif']['Orientation'] : null;
|
||||
}
|
||||
|
||||
public function getFilepath(): string
|
||||
{
|
||||
return $this->filepath;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user