diff --git a/src/EncodedImage.php b/src/EncodedImage.php index d1014497..739e53b5 100644 --- a/src/EncodedImage.php +++ b/src/EncodedImage.php @@ -6,6 +6,12 @@ use Intervention\Image\Exceptions\NotWritableException; class EncodedImage { + /** + * Create new instance + * + * @param string $data + * @param string $mimetype + */ public function __construct( protected string $data, protected string $mimetype = 'application/octet-stream' @@ -13,11 +19,22 @@ class EncodedImage // } + /** + * Return mime type of encoed image data + * + * @return string + */ public function mimetype(): string { return $this->mimetype; } + /** + * Save encoded image data in file system + * + * @param string $filepath + * @return void + */ public function save(string $filepath): void { $saved = @file_put_contents($filepath, (string) $this); @@ -28,16 +45,31 @@ class EncodedImage } } + /** + * Transform encoded image data into an data uri string + * + * @return string + */ public function toDataUri(): string { return sprintf('data:%s;base64,%s', $this->mimetype, base64_encode($this->data)); } + /** + * Cast encoded image object to string + * + * @return string + */ public function toString(): string { return $this->data; } + /** + * Create file pointer from encoded image + * + * @return resource + */ public function toFilePointer() { $pointer = fopen('php://temp', 'rw'); @@ -47,6 +79,21 @@ class EncodedImage return $pointer; } + /** + * Return byte size of encoded image + * + * @return int + */ + public function size(): int + { + return mb_strlen($this->data); + } + + /** + * Cast encoded image object to string + * + * @return string + */ public function __toString(): string { return $this->toString();