Skip to content

Commit

Permalink
replace resource with GdImage (#326)
Browse files Browse the repository at this point in the history
fixes #325
  • Loading branch information
rasteiner authored Jun 5, 2023
1 parent e3d4c8c commit b25690f
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions src/claviska/SimpleImage.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
namespace claviska;

use Exception;
use GdImage;
use League\ColorExtractor\Color;
use League\ColorExtractor\ColorExtractor;
use League\ColorExtractor\Palette;
Expand Down Expand Up @@ -64,7 +65,7 @@ class SimpleImage

protected array $flags;

protected $image;
protected $image = null;

protected string $mimeType;

Expand Down Expand Up @@ -115,10 +116,7 @@ public function __construct(string $image = '', array $flags = [])
*/
public function __destruct()
{
//Check for a valid GDimage instance
$type_check = (gettype($this->image) == 'object' && $this->image::class == 'GdImage');

if (is_resource($this->image) && $type_check) {
if ($this->image instanceof GdImage) {
imagedestroy($this->image);
}
}
Expand Down Expand Up @@ -650,8 +648,8 @@ public function getWidth(): int
/**
* Same as PHP's imagecopymerge, but works with transparent images. Used internally for overlay.
*
* @param resource $dstIm Destination image link resource.
* @param resource $srcIm Source image link resource.
* @param GdImage $dstIm Destination image.
* @param GdImage $srcIm Source image.
* @param int $dstX x-coordinate of destination point.
* @param int $dstY y-coordinate of destination point.
* @param int $srcX x-coordinate of source point.
Expand All @@ -660,7 +658,7 @@ public function getWidth(): int
* @param int $srcH Source height.
* @return bool true if success.
*/
protected static function imageCopyMergeAlpha($dstIm, $srcIm, int $dstX, int $dstY, int $srcX, int $srcY, int $srcW, int $srcH, int $pct): bool
protected static function imageCopyMergeAlpha(GdImage $dstIm, GdImage $srcIm, int $dstX, int $dstY, int $srcX, int $srcY, int $srcW, int $srcH, int $pct): bool
{
// Are we merging with transparency?
if ($pct < 100) {
Expand Down

0 comments on commit b25690f

Please sign in to comment.