mirror of
https://github.com/Intervention/image.git
synced 2025-02-07 14:20:37 +01:00
Merge pull request #654 from briedis/master
Fixed issue when reading image from stream if stream is not seekable
This commit is contained in:
commit
04e50a2d90
@ -31,7 +31,7 @@ abstract class AbstractDecoder
|
||||
/**
|
||||
* Initiates new image from Imagick object
|
||||
*
|
||||
* @param Imagick $object
|
||||
* @param \Imagick $object
|
||||
* @return \Intervention\Image\Image
|
||||
*/
|
||||
abstract public function initFromImagick(\Imagick $object);
|
||||
@ -79,9 +79,18 @@ abstract class AbstractDecoder
|
||||
public function initFromStream($stream)
|
||||
{
|
||||
$offset = ftell($stream);
|
||||
rewind($stream);
|
||||
$shouldAndCanSeek = $offset !== 0 && $this->isStreamSeekable($stream);
|
||||
|
||||
if ($shouldAndCanSeek) {
|
||||
rewind($stream);
|
||||
}
|
||||
|
||||
$data = @stream_get_contents($stream);
|
||||
fseek($stream, $offset);
|
||||
|
||||
if ($shouldAndCanSeek) {
|
||||
fseek($stream, $offset);
|
||||
}
|
||||
|
||||
if ($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
|
||||
*
|
||||
|
Loading…
x
Reference in New Issue
Block a user