Update Simple Image Class to 3.6.3
This commit is contained in:
parent
42952a5433
commit
d2f7c79cf6
1 changed files with 30 additions and 13 deletions
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
//
|
||||
// SimpleImage v3.6.0
|
||||
// SimpleImage v3.6.3
|
||||
//
|
||||
// A PHP class that makes working with images as simple as possible.
|
||||
//
|
||||
|
@ -69,7 +69,10 @@ class SimpleImage {
|
|||
* Destroys the image resource.
|
||||
*/
|
||||
public function __destruct() {
|
||||
if($this->image !== null && is_resource($this->image) && get_resource_type($this->image) === 'gd') {
|
||||
//Check for a valid GDimage instance
|
||||
$type_check = (gettype($this->image) == "object" && get_class($this->image) == "GdImage");
|
||||
|
||||
if($this->image !== null && is_resource($this->image) && $type_check) {
|
||||
imagedestroy($this->image);
|
||||
}
|
||||
}
|
||||
|
@ -128,7 +131,7 @@ class SimpleImage {
|
|||
fclose($handle);
|
||||
|
||||
// Get image info
|
||||
$info = getimagesize($file);
|
||||
$info = @getimagesize($file);
|
||||
if($info === false) {
|
||||
throw new \Exception("Invalid image file: $file", self::ERR_INVALID_IMAGE);
|
||||
}
|
||||
|
@ -587,13 +590,27 @@ class SimpleImage {
|
|||
$y1 = self::keepWithin($y1, 0, $this->getHeight());
|
||||
$y2 = self::keepWithin($y2, 0, $this->getHeight());
|
||||
|
||||
// Avoid using native imagecrop() because of a bug with PNG transparency
|
||||
$dstW = abs($x2 - $x1);
|
||||
$dstH = abs($y2 - $y1);
|
||||
$newImage = imagecreatetruecolor($dstW, $dstH);
|
||||
$transparentColor = imagecolorallocatealpha($newImage, 0, 0, 0, 127);
|
||||
imagecolortransparent($newImage, $transparentColor);
|
||||
imagefill($newImage, 0, 0, $transparentColor);
|
||||
|
||||
// Crop it
|
||||
$this->image = imagecrop($this->image, [
|
||||
'x' => min($x1, $x2),
|
||||
'y' => min($y1, $y2),
|
||||
'width' => abs($x2 - $x1),
|
||||
'height' => abs($y2 - $y1)
|
||||
]);
|
||||
imagecopyresampled(
|
||||
$newImage,
|
||||
$this->image,
|
||||
0, 0, min($x1, $x2), min($y1, $y2),
|
||||
$dstW,
|
||||
$dstH,
|
||||
$dstW,
|
||||
$dstH
|
||||
);
|
||||
|
||||
// Swap out the new image
|
||||
$this->image = $newImage;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
@ -1361,7 +1378,7 @@ class SimpleImage {
|
|||
imagefilledarc($tempImage->image, $x, $y, $width+$thickness, $height+$thickness, $start, $end, $tempColor, IMG_ARC_PIE);
|
||||
|
||||
// Draw a smaller ellipse filled with red|blue (-$thickness pixels)
|
||||
$tempColor = ($color == 'red') ? 'blue' : 'red';
|
||||
$tempColor = (self::normalizeColor($color)['red'] == 255) ? 'blue' : 'red';
|
||||
$tempColor = $tempImage->allocateColor($tempColor);
|
||||
imagefilledarc($tempImage->image, $x, $y, $width-$thickness, $height-$thickness, $start, $end, $tempColor, IMG_ARC_PIE);
|
||||
|
||||
|
@ -1443,7 +1460,7 @@ class SimpleImage {
|
|||
imagefilledellipse($tempImage->image, $x, $y, $width+$thickness, $height+$thickness, $tempColor);
|
||||
|
||||
// Draw a smaller ellipse filled with red|blue (-$thickness pixels)
|
||||
$tempColor = ($color == 'red') ? 'blue' : 'red';
|
||||
$tempColor = (self::normalizeColor($color)['red'] == 255) ? 'blue' : 'red';
|
||||
$tempColor = $tempImage->allocateColor($tempColor);
|
||||
imagefilledellipse($tempImage->image, $x, $y, $width-$thickness, $height-$thickness, $tempColor);
|
||||
|
||||
|
@ -1603,7 +1620,7 @@ class SimpleImage {
|
|||
$tempImage->roundedRectangle($x1, $y1, $x2, $y2, $radius, $color,'filled');
|
||||
|
||||
// Draw a smaller rectangle filled with red|blue (-$thickness pixels on each side)
|
||||
$tempColor = ($color == 'red') ? 'blue' : 'red';
|
||||
$tempColor = (self::normalizeColor($color)['red'] == 255) ? 'blue' : 'red';
|
||||
$radius = $radius - $thickness;
|
||||
$radius = self::keepWithin($radius, 0, $radius);
|
||||
$tempImage->roundedRectangle(
|
||||
|
@ -2131,4 +2148,4 @@ class SimpleImage {
|
|||
throw new \Exception("Invalid color value: $color", self::ERR_INVALID_COLOR);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue