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
|
<?php
|
||||||
//
|
//
|
||||||
// SimpleImage v3.6.0
|
// SimpleImage v3.6.3
|
||||||
//
|
//
|
||||||
// A PHP class that makes working with images as simple as possible.
|
// A PHP class that makes working with images as simple as possible.
|
||||||
//
|
//
|
||||||
|
@ -69,7 +69,10 @@ class SimpleImage {
|
||||||
* Destroys the image resource.
|
* Destroys the image resource.
|
||||||
*/
|
*/
|
||||||
public function __destruct() {
|
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);
|
imagedestroy($this->image);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -128,7 +131,7 @@ class SimpleImage {
|
||||||
fclose($handle);
|
fclose($handle);
|
||||||
|
|
||||||
// Get image info
|
// Get image info
|
||||||
$info = getimagesize($file);
|
$info = @getimagesize($file);
|
||||||
if($info === false) {
|
if($info === false) {
|
||||||
throw new \Exception("Invalid image file: $file", self::ERR_INVALID_IMAGE);
|
throw new \Exception("Invalid image file: $file", self::ERR_INVALID_IMAGE);
|
||||||
}
|
}
|
||||||
|
@ -587,13 +590,27 @@ class SimpleImage {
|
||||||
$y1 = self::keepWithin($y1, 0, $this->getHeight());
|
$y1 = self::keepWithin($y1, 0, $this->getHeight());
|
||||||
$y2 = self::keepWithin($y2, 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
|
// Crop it
|
||||||
$this->image = imagecrop($this->image, [
|
imagecopyresampled(
|
||||||
'x' => min($x1, $x2),
|
$newImage,
|
||||||
'y' => min($y1, $y2),
|
$this->image,
|
||||||
'width' => abs($x2 - $x1),
|
0, 0, min($x1, $x2), min($y1, $y2),
|
||||||
'height' => abs($y2 - $y1)
|
$dstW,
|
||||||
]);
|
$dstH,
|
||||||
|
$dstW,
|
||||||
|
$dstH
|
||||||
|
);
|
||||||
|
|
||||||
|
// Swap out the new image
|
||||||
|
$this->image = $newImage;
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
@ -1361,7 +1378,7 @@ class SimpleImage {
|
||||||
imagefilledarc($tempImage->image, $x, $y, $width+$thickness, $height+$thickness, $start, $end, $tempColor, IMG_ARC_PIE);
|
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)
|
// 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);
|
$tempColor = $tempImage->allocateColor($tempColor);
|
||||||
imagefilledarc($tempImage->image, $x, $y, $width-$thickness, $height-$thickness, $start, $end, $tempColor, IMG_ARC_PIE);
|
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);
|
imagefilledellipse($tempImage->image, $x, $y, $width+$thickness, $height+$thickness, $tempColor);
|
||||||
|
|
||||||
// Draw a smaller ellipse filled with red|blue (-$thickness pixels)
|
// 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);
|
$tempColor = $tempImage->allocateColor($tempColor);
|
||||||
imagefilledellipse($tempImage->image, $x, $y, $width-$thickness, $height-$thickness, $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');
|
$tempImage->roundedRectangle($x1, $y1, $x2, $y2, $radius, $color,'filled');
|
||||||
|
|
||||||
// Draw a smaller rectangle filled with red|blue (-$thickness pixels on each side)
|
// 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 = $radius - $thickness;
|
||||||
$radius = self::keepWithin($radius, 0, $radius);
|
$radius = self::keepWithin($radius, 0, $radius);
|
||||||
$tempImage->roundedRectangle(
|
$tempImage->roundedRectangle(
|
||||||
|
|
Loading…
Reference in a new issue