1
0
mirror of https://github.com/Intervention/image.git synced 2025-09-02 18:32:56 +02:00

Add docblocks

This commit is contained in:
Oliver Vogel
2023-10-22 19:30:04 +02:00
parent 2754da5e6f
commit 01854edc07

View File

@@ -6,6 +6,12 @@ use Intervention\Image\Exceptions\NotWritableException;
class EncodedImage class EncodedImage
{ {
/**
* Create new instance
*
* @param string $data
* @param string $mimetype
*/
public function __construct( public function __construct(
protected string $data, protected string $data,
protected string $mimetype = 'application/octet-stream' 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 public function mimetype(): string
{ {
return $this->mimetype; return $this->mimetype;
} }
/**
* Save encoded image data in file system
*
* @param string $filepath
* @return void
*/
public function save(string $filepath): void public function save(string $filepath): void
{ {
$saved = @file_put_contents($filepath, (string) $this); $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 public function toDataUri(): string
{ {
return sprintf('data:%s;base64,%s', $this->mimetype, base64_encode($this->data)); return sprintf('data:%s;base64,%s', $this->mimetype, base64_encode($this->data));
} }
/**
* Cast encoded image object to string
*
* @return string
*/
public function toString(): string public function toString(): string
{ {
return $this->data; return $this->data;
} }
/**
* Create file pointer from encoded image
*
* @return resource
*/
public function toFilePointer() public function toFilePointer()
{ {
$pointer = fopen('php://temp', 'rw'); $pointer = fopen('php://temp', 'rw');
@@ -47,6 +79,21 @@ class EncodedImage
return $pointer; 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 public function __toString(): string
{ {
return $this->toString(); return $this->toString();