Version 4.2.0
This commit is contained in:
1 parent
0dc2aee5ed
commit
96997ddd8e
2074 files changed
+125454
-55780
No files matched your search
@@ -1,12 +1,11 @@
|
||||
<?php
|
||||
/**
|
||||
* @brief Image Class - ImageMagick
|
||||
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
|
||||
* @copyright (c) 2001 - 2016 Invision Power Services, Inc.
|
||||
* @license http://www.invisionpower.com/legal/standards/
|
||||
* @package IPS Community Suite
|
||||
* @author <a href='https://www.invisioncommunity.com'>Invision Power Services, Inc.</a>
|
||||
* @copyright (c) Invision Power Services, Inc.
|
||||
* @license https://www.invisioncommunity.com/legal/standards/
|
||||
* @package Invision Community
|
||||
* @since 06 Mar 2014
|
||||
* @version SVN_VERSION_NUMBER
|
||||
*/
|
||||
|
||||
namespace IPS\Image;
|
||||
@@ -26,7 +25,7 @@ class _Imagemagick extends \IPS\Image
|
||||
/**
|
||||
* @brief Temporary filename
|
||||
*/
|
||||
protected $tempFile;
|
||||
protected $tempFile = NULL;
|
||||
|
||||
/**
|
||||
* @brief Imagick object
|
||||
@@ -36,12 +35,19 @@ class _Imagemagick extends \IPS\Image
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param string $contents Contents
|
||||
* @param string|NULL $contents Contents
|
||||
* @param bool $noImage We are creating a new instance of the object internally and are not passing an image string
|
||||
* @return void
|
||||
* @throws \InvalidArgumentException
|
||||
*/
|
||||
public function __construct( $contents )
|
||||
public function __construct( $contents, $noImage=FALSE )
|
||||
{
|
||||
/* If we are just creating an instance of the object without passing image contents as a string, return now */
|
||||
if( $noImage === TRUE )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
$this->tempFile = tempnam( \IPS\TEMP_DIRECTORY, 'imagick' );
|
||||
\file_put_contents( $this->tempFile, $contents );
|
||||
|
||||
@@ -55,7 +61,7 @@ class _Imagemagick extends \IPS\Image
|
||||
}
|
||||
|
||||
/* Set quality (if image format is JPEG) */
|
||||
if ( in_array( $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 );
|
||||
}
|
||||
@@ -71,7 +77,10 @@ class _Imagemagick extends \IPS\Image
|
||||
*/
|
||||
public function __destruct()
|
||||
{
|
||||
unlink( $this->tempFile );
|
||||
if( $this->tempFile !== NULL )
|
||||
{
|
||||
unlink( $this->tempFile );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -104,7 +113,15 @@ class _Imagemagick extends \IPS\Image
|
||||
$frame->thumbnailImage( $width, $height );
|
||||
}
|
||||
|
||||
$this->imagick = $this->imagick->deconstructImages();
|
||||
/* Needs ImageMagick 6.2.9 or higher for optimizeImageLayers */
|
||||
try
|
||||
{
|
||||
$this->imagick = $this->imagick->optimizeImageLayers();
|
||||
}
|
||||
catch( \ImagickException $e )
|
||||
{
|
||||
$this->imagick = $this->imagick->deconstructImages();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -151,7 +168,15 @@ class _Imagemagick extends \IPS\Image
|
||||
$frame->setImagePage($point2X - $point1X, $point2Y - $point1Y, 0, 0);
|
||||
}
|
||||
|
||||
$this->imagick = $this->imagick->deconstructImages();
|
||||
/* Needs ImageMagick 6.2.9 or higher for optimizeImageLayers */
|
||||
try
|
||||
{
|
||||
$this->imagick = $this->imagick->optimizeImageLayers();
|
||||
}
|
||||
catch( \ImagickException $e )
|
||||
{
|
||||
$this->imagick = $this->imagick->deconstructImages();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -232,4 +257,58 @@ class _Imagemagick extends \IPS\Image
|
||||
$this->imagick->setImageOrientation($orientation);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Can we write text reliably on an image?
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function canWriteText()
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new blank canvas image
|
||||
*
|
||||
* @param int $width Width
|
||||
* @param int $height Height
|
||||
* @param array $rgb Color to use for bg
|
||||
* @return \IPS\Image
|
||||
*/
|
||||
public static function newImageCanvas( $width, $height, $rgb )
|
||||
{
|
||||
$obj = new static( NULL, TRUE );
|
||||
$obj->imagick = new \Imagick();
|
||||
$obj->width = $width;
|
||||
$obj->height = $height;
|
||||
$obj->type = 'png';
|
||||
$pixel = new \ImagickPixel( "rgba({$rgb[0]}, {$rgb[1]}, {$rgb[2]}, 1)" );
|
||||
|
||||
$obj->imagick->newImage( $width, $height, $pixel );
|
||||
$obj->imagick->setImageFormat( "png" );
|
||||
|
||||
return $obj;
|
||||
}
|
||||
|
||||
/**
|
||||
* Write text on our image
|
||||
*
|
||||
* @param string $text Text
|
||||
* @param string $font Path to font to use
|
||||
* @param int $size Size of text
|
||||
* @return void
|
||||
*/
|
||||
public function write( $text, $font, $size )
|
||||
{
|
||||
$draw = new \ImagickDraw();
|
||||
$draw->setTextAntialias( true );
|
||||
$draw->setGravity( \Imagick::GRAVITY_CENTER );
|
||||
$draw->setFont( $font );
|
||||
$draw->setFontSize( $size );
|
||||
|
||||
$draw->setFillColor( "rgb( 255, 255, 255 )" );
|
||||
|
||||
$this->imagick->annotateImage( $draw, 0, 0, 0, $text );
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user