Version 4.6.0
This commit is contained in:
1 parent
f79dcf067a
commit
517a5e1f70
2036 files changed
+110041
-26162
No files matched your search
@@ -148,6 +148,13 @@ class _Gd extends \IPS\Image
|
||||
|
||||
imagepng( $this->image, NULL, $quality );
|
||||
break;
|
||||
|
||||
case 'webp':
|
||||
$quality = \IPS\Settings::i()->image_jpg_quality ?: 85;
|
||||
|
||||
imagewebp( $this->image, NULL, $quality );
|
||||
break;
|
||||
|
||||
}
|
||||
return ob_get_clean();
|
||||
}
|
||||
@@ -390,4 +397,21 @@ class _Gd extends \IPS\Image
|
||||
{
|
||||
return (bool) \function_exists( 'imagettfbbox' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an array of supported extensions
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function supportedExtensions()
|
||||
{
|
||||
$extensions = static::$imageExtensions;
|
||||
|
||||
if( isset( gd_info()['WebP Support'] ) and gd_info()['WebP Support'] )
|
||||
{
|
||||
$extensions[] = 'webp';
|
||||
}
|
||||
|
||||
return $extensions;
|
||||
}
|
||||
}
|
||||
+50
-9
@@ -30,7 +30,7 @@ abstract class _Image
|
||||
/**
|
||||
* @brief Image Mime Types
|
||||
*/
|
||||
public static $imageMimes = array( 'image/gif', 'image/jpeg', 'image/pjpeg', 'image/png' );
|
||||
public static $imageMimes = array( 'image/gif', 'image/jpeg', 'image/pjpeg', 'image/png', 'image/webp' );
|
||||
|
||||
/**
|
||||
* @brief Allow EXIF processing
|
||||
@@ -58,6 +58,7 @@ abstract class _Image
|
||||
* @param string $contents Contents
|
||||
* @return \IPS\Image
|
||||
* @throws \InvalidArgumentException
|
||||
* @link https://en.wikipedia.org/wiki/List_of_file_signatures
|
||||
*/
|
||||
public static function create( $contents )
|
||||
{
|
||||
@@ -74,21 +75,34 @@ abstract class _Image
|
||||
),
|
||||
'png' => array(
|
||||
'89' . '50' . '4e' . '47' . '0d' . '0a' . '1a' . '0a'
|
||||
)
|
||||
);
|
||||
$bytesNeeded = max( array_map( 'strlen', array_map( 'hex2bin', array_merge( $signatures['gif'], $signatures['jpeg'], $signatures['png'] ) ) ) );
|
||||
),
|
||||
);
|
||||
|
||||
$bytesNeeded = max( array_merge( array_map( 'strlen', array_map( 'hex2bin', array_merge( $signatures['gif'], $signatures['jpeg'], $signatures['png'] ) ) ), array( 12 ) ) );
|
||||
$fileHeader = \substr( $contents, 0, $bytesNeeded );
|
||||
foreach ( $signatures as $type => $_signatures )
|
||||
|
||||
/* Try webp first since it's special: RIFF, 4 bytes for size, WEBP: */
|
||||
if ( bin2hex( \substr( $fileHeader, 0, 4 ) ) === '52' . '49' . '46' . '46' AND bin2hex( \substr( $fileHeader, 8, 4 ) ) === '57' . '45' . '42' . '50' )
|
||||
{
|
||||
foreach ( $_signatures as $signature )
|
||||
$imageType = 'webp';
|
||||
}
|
||||
|
||||
/* If it's not webp, try the rest of the image types */
|
||||
if( !$imageType )
|
||||
{
|
||||
foreach ( $signatures as $type => $_signatures )
|
||||
{
|
||||
if ( bin2hex( \substr( $fileHeader, 0, \strlen( hex2bin( $signature ) ) ) ) === $signature )
|
||||
foreach ( $_signatures as $signature )
|
||||
{
|
||||
$imageType = $type;
|
||||
break 2;
|
||||
if ( bin2hex( \substr( $fileHeader, 0, \strlen( hex2bin( $signature ) ) ) ) === $signature )
|
||||
{
|
||||
$imageType = $type;
|
||||
break 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( $imageType === NULL )
|
||||
{
|
||||
throw new \InvalidArgumentException;
|
||||
@@ -450,4 +464,31 @@ abstract class _Image
|
||||
return Image\Gd::canWriteText();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an array of supported extensions
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function supportedExtensions()
|
||||
{
|
||||
if( \IPS\Settings::i()->image_suite == 'imagemagick' and class_exists( 'Imagick', FALSE ) )
|
||||
{
|
||||
return Image\Imagemagick::supportedExtensions();
|
||||
}
|
||||
else
|
||||
{
|
||||
return Image\Gd::supportedExtensions();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Is this a square image ( width == height )
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isSquare() : bool
|
||||
{
|
||||
return $this->width === $this->height;
|
||||
}
|
||||
}
|
||||
@@ -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', 'webp' ) ) )
|
||||
{
|
||||
$this->imagick->setImageCompressionQuality( (int) \IPS\Settings::i()->image_jpg_quality ?: 85 );
|
||||
}
|
||||
@@ -343,4 +343,21 @@ class _Imagemagick extends \IPS\Image
|
||||
|
||||
$this->imagick->annotateImage( $draw, 0, 0, 0, $text );
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an array of supported extensions
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function supportedExtensions()
|
||||
{
|
||||
$extensions = static::$imageExtensions;
|
||||
|
||||
if( \in_array( 'WEBP', \Imagick::queryFormats() ) )
|
||||
{
|
||||
$extensions[] = 'webp';
|
||||
}
|
||||
|
||||
return $extensions;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user