mirror of
https://github.com/Intervention/image.git
synced 2025-08-25 23:06:13 +02:00
Fixed issue when reading image from stream if stream is not seekable (Amazon S3, for example)
This commit is contained in:
@@ -31,7 +31,7 @@ abstract class AbstractDecoder
|
|||||||
/**
|
/**
|
||||||
* Initiates new image from Imagick object
|
* Initiates new image from Imagick object
|
||||||
*
|
*
|
||||||
* @param Imagick $object
|
* @param \Imagick $object
|
||||||
* @return \Intervention\Image\Image
|
* @return \Intervention\Image\Image
|
||||||
*/
|
*/
|
||||||
abstract public function initFromImagick(\Imagick $object);
|
abstract public function initFromImagick(\Imagick $object);
|
||||||
@@ -79,9 +79,18 @@ abstract class AbstractDecoder
|
|||||||
public function initFromStream($stream)
|
public function initFromStream($stream)
|
||||||
{
|
{
|
||||||
$offset = ftell($stream);
|
$offset = ftell($stream);
|
||||||
rewind($stream);
|
$shouldAndCanSeek = $offset !== 0 && $this->isStreamSeekable($stream);
|
||||||
|
|
||||||
|
if ($shouldAndCanSeek) {
|
||||||
|
rewind($stream);
|
||||||
|
}
|
||||||
|
|
||||||
$data = @stream_get_contents($stream);
|
$data = @stream_get_contents($stream);
|
||||||
fseek($stream, $offset);
|
|
||||||
|
if ($shouldAndCanSeek) {
|
||||||
|
fseek($stream, $offset);
|
||||||
|
}
|
||||||
|
|
||||||
if ($data) {
|
if ($data) {
|
||||||
return $this->initFromBinary($data);
|
return $this->initFromBinary($data);
|
||||||
}
|
}
|
||||||
@@ -91,6 +100,18 @@ abstract class AbstractDecoder
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if we can move the pointer for this stream
|
||||||
|
*
|
||||||
|
* @param resource $stream
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
private function isStreamSeekable($stream)
|
||||||
|
{
|
||||||
|
$metadata = stream_get_meta_data($stream);
|
||||||
|
return $metadata['seekable'];
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Determines if current source data is GD resource
|
* Determines if current source data is GD resource
|
||||||
*
|
*
|
||||||
|
Reference in New Issue
Block a user