if (is_resource($this->resource)) {
return true;
}
- if (is_object($this->resource) && get_class($this->resource) === 'GdImage') {
+ if (is_object($this->resource) && get_class($this->resource) === \GdImage::class) {
return true;
}
}
/**
- * @param resource Returns the image resource in any.
+ * @param resource|\GdImage $resource
* @throws \InvalidArgumentException in case the supplied resource does not have the type "gd"
*/
public function setResource($resource) {
return;
}
// PHP 8 has real objects for GD stuff
- if (is_object($resource) && get_class($resource) === 'GdImage') {
+ if (is_object($resource) && get_class($resource) === \GdImage::class) {
$this->resource = $resource;
return;
}
}
/**
- * @return resource Returns the image resource in any.
+ * @return resource|\GdImage Returns the image resource in any.
*/
public function resource() {
return $this->resource;
* It is the responsibility of the caller to position the pointer at the correct place and to close the handle again.
*
* @param resource $handle
- * @return resource|false An image resource or false on error
+ * @return resource|\GdImage|false An image resource or false on error
*/
public function loadFromFileHandle($handle) {
$contents = stream_get_contents($handle);
* Loads an image from a local file.
*
* @param bool|string $imagePath The path to a local file.
- * @return bool|resource An image resource or false on error
+ * @return bool|resource|\GdImage An image resource or false on error
*/
public function loadFromFile($imagePath = false) {
// exif_imagetype throws "read error!" if file is less than 12 byte
* Loads an image from a string of data.
*
* @param string $str A string of image data as read from a file.
- * @return bool|resource An image resource or false on error
+ * @return bool|resource|\GdImage An image resource or false on error
*/
public function loadFromData($str) {
- if (is_resource($str)) {
+ if (!is_string($str)) {
return false;
}
$this->resource = @imagecreatefromstring($str);
if ($this->fileInfo) {
$this->mimeType = $this->fileInfo->buffer($str);
}
- if (is_resource($this->resource)) {
+ if ($this->valid()) {
imagealphablending($this->resource, false);
imagesavealpha($this->resource, true);
}
* Loads an image from a base64 encoded string.
*
* @param string $str A string base64 encoded string of image data.
- * @return bool|resource An image resource or false on error
+ * @return bool|resource|\GdImage An image resource or false on error
*/
public function loadFromBase64($str) {
if (!is_string($str)) {
* @param string $fileName <p>
* Path to the BMP image.
* </p>
- * @return bool|resource an image resource identifier on success, <b>FALSE</b> on errors.
+ * @return bool|resource|\GdImage an image resource identifier on success, <b>FALSE</b> on errors.
*/
private function imagecreatefrombmp($fileName) {
if (!($fh = fopen($fileName, 'rb'))) {
$result = $this->resizeNew($maxSize);
imagedestroy($this->resource);
$this->resource = $result;
- return is_resource($result);
+ return $this->valid();
}
/**
* @param $maxSize
- * @return resource | bool
+ * @return resource|bool|\GdImage
*/
private function resizeNew($maxSize) {
if (!$this->valid()) {
$result = $this->preciseResizeNew($width, $height);
imagedestroy($this->resource);
$this->resource = $result;
- return is_resource($result);
+ return $this->valid();
}
/**
* @param int $width
* @param int $height
- * @return resource | bool
+ * @return resource|bool|\GdImage
*/
public function preciseResizeNew(int $width, int $height) {
if (!$this->valid()) {
$result = $this->cropNew($x, $y, $w, $h);
imagedestroy($this->resource);
$this->resource = $result;
- return is_resource($result);
+ return $this->valid();
}
/**
* @link http://www.programmierer-forum.de/imagebmp-gute-funktion-gefunden-t143716.htm
* @author mgutt <marc@gutt.it>
* @version 1.00
- * @param resource $im
+ * @param resource|\GdImage $im
* @param string $fileName [optional] <p>The path to save the file to.</p>
* @param int $bit [optional] <p>Bit depth, (default is 24).</p>
* @param int $compression [optional]