Version 4.6.0
This commit is contained in:
1 parent
f79dcf067a
commit
517a5e1f70
2036 files changed
+110041
-26162
No files matched your search
+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;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user