diff --git a/src/Drivers/Abstract/Decoders/AbstractDecoder.php b/src/Drivers/Abstract/Decoders/AbstractDecoder.php index 76f4ba95..a7c6df54 100644 --- a/src/Drivers/Abstract/Decoders/AbstractDecoder.php +++ b/src/Drivers/Abstract/Decoders/AbstractDecoder.php @@ -7,11 +7,14 @@ use Intervention\Image\Exceptions\DecoderException; use Intervention\Image\Interfaces\ColorInterface; use Intervention\Image\Interfaces\DecoderInterface; use Intervention\Image\Interfaces\ImageInterface; +use Intervention\Image\Traits\CanBuildFilePointer; use Intervention\MimeSniffer\MimeSniffer; use Intervention\MimeSniffer\AbstractType; abstract class AbstractDecoder implements DecoderInterface { + use CanBuildFilePointer; + public function __construct(protected ?AbstractDecoder $successor = null) { // @@ -49,9 +52,7 @@ abstract class AbstractDecoder implements DecoderInterface } try { - $pointer = fopen('php://temp', 'rw'); - fputs($pointer, $image_data); - rewind($pointer); + $pointer = $this->buildFilePointer($image_data); $data = @exif_read_data($pointer, null, true); fclose($pointer); } catch (Exception $e) { diff --git a/src/GenericData.php b/src/GenericData.php index 4aca16f6..25381198 100644 --- a/src/GenericData.php +++ b/src/GenericData.php @@ -4,9 +4,12 @@ namespace Intervention\Image; use Intervention\Image\Exceptions\NotWritableException; use Intervention\Image\Interfaces\GenericDataInterface; +use Intervention\Image\Traits\CanBuildFilePointer; class GenericData implements GenericDataInterface { + use CanBuildFilePointer; + /** * Create new instance * @@ -50,11 +53,7 @@ class GenericData implements GenericDataInterface */ public function toFilePointer() { - $pointer = fopen('php://temp', 'rw'); - fputs($pointer, $this->toString()); - rewind($pointer); - - return $pointer; + return $this->buildFilePointer($this->toString()); } /** diff --git a/src/Traits/CanBuildFilePointer.php b/src/Traits/CanBuildFilePointer.php new file mode 100644 index 00000000..912f72a5 --- /dev/null +++ b/src/Traits/CanBuildFilePointer.php @@ -0,0 +1,15 @@ +