Version 4.5.0
This commit is contained in:
1 parent
1a0c7fd3c2
commit
f79dcf067a
3791 files changed
+248032
-76372
No files matched your search
+8
-8
@@ -11,7 +11,7 @@
|
||||
namespace IPS\Image;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
{
|
||||
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
exit;
|
||||
@@ -47,9 +47,9 @@ class _Gd extends \IPS\Image
|
||||
$this->image = @imagecreatefromstring( $contents );
|
||||
if ( $this->image === FALSE )
|
||||
{
|
||||
if ( $error = error_get_last() )
|
||||
if ( $error = \IPS\IPS::$lastError )
|
||||
{
|
||||
throw new \InvalidArgumentException( $error['message'], $error['type'] );
|
||||
throw new \InvalidArgumentException( $error->getMessage(), $error->getCode() );
|
||||
}
|
||||
|
||||
throw new \InvalidArgumentException;
|
||||
@@ -98,8 +98,8 @@ class _Gd extends \IPS\Image
|
||||
$fontColor = imagecolorallocate( $this->image, 255, 255, 255 );
|
||||
|
||||
$box = imagettfbbox( $size, 0, $font, $text );
|
||||
$x = intval( ( imagesx( $this->image ) - abs( max( $box[2], $box[4] ) ) ) / 2 ) - ( ( $box[0] > 0 ) ? ( $box[0] / 2.5 ) : 0 );
|
||||
$y = intval( ( imagesy( $this->image ) + ( abs( $box[5] ) - abs( $box[1] ) ) ) / 2 );
|
||||
$x = \intval( ( imagesx( $this->image ) - abs( max( $box[2], $box[4] ) ) ) / 2 ) - ( ( $box[0] > 0 ) ? ( $box[0] / 2.5 ) : 0 );
|
||||
$y = \intval( ( imagesy( $this->image ) + ( abs( $box[5] ) - abs( $box[1] ) ) ) / 2 );
|
||||
|
||||
imagettftext( $this->image, $size, 0, $x, $y, $fontColor, $font, $text );
|
||||
}
|
||||
@@ -111,7 +111,7 @@ class _Gd extends \IPS\Image
|
||||
*/
|
||||
public function __destruct()
|
||||
{
|
||||
if( is_resource( $this->image ) )
|
||||
if( \is_resource( $this->image ) )
|
||||
{
|
||||
imagedestroy( $this->image );
|
||||
}
|
||||
@@ -322,7 +322,7 @@ class _Gd extends \IPS\Image
|
||||
*
|
||||
* @param \IPS\Image $image Image to impose
|
||||
* @param int $x Location to impose to, x axis
|
||||
* @param int y Location to impose to, y axis
|
||||
* @param int $y Location to impose to, y axis
|
||||
* @return void
|
||||
*/
|
||||
public function impose( $image, $x=0, $y=0 )
|
||||
@@ -388,6 +388,6 @@ class _Gd extends \IPS\Image
|
||||
*/
|
||||
public static function canWriteText()
|
||||
{
|
||||
return (bool) function_exists( 'imagettfbbox' );
|
||||
return (bool) \function_exists( 'imagettfbbox' );
|
||||
}
|
||||
}
|
||||
+19
-13
@@ -11,7 +11,7 @@
|
||||
namespace IPS;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
{
|
||||
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
exit;
|
||||
@@ -32,6 +32,11 @@ abstract class _Image
|
||||
*/
|
||||
public static $imageMimes = array( 'image/gif', 'image/jpeg', 'image/pjpeg', 'image/png' );
|
||||
|
||||
/**
|
||||
* @brief Allow EXIF processing
|
||||
*/
|
||||
public static $exifEnabled = TRUE;
|
||||
|
||||
/**
|
||||
* Determine if EXIF extraction is supported
|
||||
*
|
||||
@@ -39,7 +44,7 @@ abstract class _Image
|
||||
*/
|
||||
public static function exifSupported()
|
||||
{
|
||||
return function_exists( 'exif_read_data' );
|
||||
return \function_exists( 'exif_read_data' ) and static::$exifEnabled;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -71,7 +76,7 @@ abstract class _Image
|
||||
'89' . '50' . '4e' . '47' . '0d' . '0a' . '1a' . '0a'
|
||||
)
|
||||
);
|
||||
$bytesNeeded = max( array_map( 'strlen', array_map( 'hex2bin', call_user_func_array( 'array_merge', $signatures ) ) ) );
|
||||
$bytesNeeded = max( array_map( 'strlen', array_map( 'hex2bin', array_merge( $signatures['gif'], $signatures['jpeg'], $signatures['png'] ) ) ) );
|
||||
$fileHeader = \substr( $contents, 0, $bytesNeeded );
|
||||
foreach ( $signatures as $type => $_signatures )
|
||||
{
|
||||
@@ -100,8 +105,8 @@ abstract class _Image
|
||||
}
|
||||
$obj->type = $imageType;
|
||||
|
||||
/* Animated? */
|
||||
if ( $obj->type === 'gif' and (boolean) preg_match( '#(\x00\x21\xF9\x04.{4}\x00\x2C.*){2,}#s', $contents ) )
|
||||
/* Animated? @see https://www.php.net/manual/en/function.imagecreatefromgif.php#102915 */
|
||||
if ( $obj->type === 'gif' and (boolean) preg_match( '#\x00\x21\xF9\x04.{4}\x00(\x2C|\x21)#s', $contents ) )
|
||||
{
|
||||
$obj->isAnimatedGif = TRUE;
|
||||
$obj->contents = $contents;
|
||||
@@ -200,15 +205,15 @@ abstract class _Image
|
||||
*
|
||||
* @param int|NULL $maxWidth Max Width (in pixels) or NULL
|
||||
* @param int|NULL $maxHeight Max Height (in pixels) or NULL
|
||||
* @param bool $retainRatio If TRUE, the image will keep it's current width/height ratio rather than being squashed
|
||||
* @return bool
|
||||
* @param bool $retainRatio If TRUE, the image will keep it's current width/height ratio rather than being squashed
|
||||
* @return bool Returns TRUE if it actually resized, or FALSE if it wasn't necessary
|
||||
*/
|
||||
public function resizeToMax( $maxWidth=NULL, $maxHeight=NULL, $retainRatio=TRUE )
|
||||
{
|
||||
/* If the image is smaller than max we can skip */
|
||||
if( ( $maxWidth == NULL or $this->width < $maxWidth ) and ( $maxHeight == NULL or $this->height < $maxHeight ) )
|
||||
{
|
||||
return TRUE;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/* Work out the maximum width/height */
|
||||
@@ -233,10 +238,11 @@ abstract class _Image
|
||||
}
|
||||
|
||||
/* And resize */
|
||||
return $this->resize( $width, $height );
|
||||
$this->resize( $width, $height );
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -267,7 +273,7 @@ abstract class _Image
|
||||
throw new \LogicException( 'NO_EXIF' );
|
||||
}
|
||||
|
||||
if( !in_array( $this->type, array( 'jpeg', 'jpg', 'jpe' ) ) )
|
||||
if( !\in_array( $this->type, array( 'jpeg', 'jpg', 'jpe' ) ) )
|
||||
{
|
||||
return array();
|
||||
}
|
||||
@@ -303,12 +309,12 @@ abstract class _Image
|
||||
/**
|
||||
* Get EXIF data, if possible
|
||||
*
|
||||
* @param string $image Image contents
|
||||
* @param string $contents Image contents
|
||||
* @return void
|
||||
*/
|
||||
public function setExifData( $contents )
|
||||
{
|
||||
if( !in_array( $this->type, array( 'jpeg', 'jpg', 'jpe' ) ) )
|
||||
if( !\in_array( $this->type, array( 'jpeg', 'jpg', 'jpe' ) ) )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
namespace IPS\Image;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
{
|
||||
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
exit;
|
||||
@@ -56,7 +56,7 @@ class _Imagemagick extends \IPS\Image
|
||||
$this->imagick = new \Imagick( $this->tempFile );
|
||||
|
||||
/* Set quality (if image format is JPEG) */
|
||||
if ( in_array( mb_strtolower( $this->imagick->getImageFormat() ), array( 'jpg', 'jpeg' ) ) )
|
||||
if ( \in_array( mb_strtolower( $this->imagick->getImageFormat() ), array( 'jpg', 'jpeg' ) ) )
|
||||
{
|
||||
$this->imagick->setImageCompressionQuality( (int) \IPS\Settings::i()->image_jpg_quality ?: 85 );
|
||||
}
|
||||
@@ -103,7 +103,7 @@ class _Imagemagick extends \IPS\Image
|
||||
|
||||
$this->imagick->stripImage();
|
||||
|
||||
if( count( $imageColorProfiles ) )
|
||||
if( \count( $imageColorProfiles ) )
|
||||
{
|
||||
foreach( $imageColorProfiles as $type => $profile )
|
||||
{
|
||||
@@ -247,6 +247,12 @@ class _Imagemagick extends \IPS\Image
|
||||
*/
|
||||
protected function setDimensions()
|
||||
{
|
||||
/* If this is a gif, we need to coalesce the image in order to get the proper dimensions */
|
||||
if ( mb_strtolower( $this->imagick->getImageFormat() ) === 'gif' )
|
||||
{
|
||||
$this->imagick = $this->imagick->coalesceImages();
|
||||
}
|
||||
|
||||
/* Set width/height */
|
||||
$this->width = $this->imagick->getImageWidth();
|
||||
$this->height = $this->imagick->getImageHeight();
|
||||
|
||||
Reference in new issue
Block a user