Version 3.2.3

This commit is contained in:
Neo committed 2025-12-19 00:34:03 -08:00
1 parent ae5c01cc78
commit 78706903a2
2641 files changed
+228363 -201264

No files matched your search

+102 -37
View File
@@ -3,19 +3,19 @@
/**
* <pre>
* Invision Power Services
* IP.Board v3.1.4
* IP.Board v3.2.3
* Image Handler: ImageMagick Library
* Last Updated: $Date: 2010-03-02 16:04:56 -0500 (Tue, 02 Mar 2010) $
* Last Updated: $Date: 2011-08-01 17:58:16 -0400 (Mon, 01 Aug 2011) $
* </pre>
*
* @author $Author: josh $
* @author $Author: bfarber $
* @copyright (c) 2001 - 2009 Invision Power Services, Inc.
* @license http://www.invisionpower.com/community/board/license.html
* @license This is NULLED!
* @package IP.Board
* @subpackage Kernel
* @link http://www.invisionpower.com
* @link http://hatynka.in
* @since Monday 5th May 2008 14:00
* @version $Revision: 380 $
* @version $Revision: 9346 $
*
* ImageMagick Example
* <code>
@@ -46,26 +46,26 @@ class classImageImagemagick extends classImage implements interfaceImage
/**
* ImageMagick Path
*
* @access private
* @access protected
* @var string Path to imagemagick binary (folder, no trailing slash)
*/
private $im_path = null;
protected $im_path = null;
/**
* Temp directory (must be writable)
*
* @access private
* @access protected
* @var string Path to a temp directory
*/
private $temp_path = '';
protected $temp_path = '';
/**
* Temp file (directory, name, .temp)
*
* @access private
* @access protected
* @var string Full path to the temp file
*/
private $temp_file = '';
protected $temp_file = '';
/**
* Image quality settings
@@ -88,19 +88,19 @@ class classImageImagemagick extends classImage implements interfaceImage
// Verify params
//---------------------------------------------------------
if( !isset($opts['image_path']) OR !$opts['image_path'] )
if( empty($opts['image_path']) )
{
$this->error = 'no_image_path';
return false;
}
if( !isset($opts['image_file']) OR !$opts['image_file'] )
if( empty($opts['image_file']) )
{
$this->error = 'no_image_file';
return false;
}
if( !isset($opts['im_path']) OR !$opts['im_path'] )
if( empty($opts['im_path']) )
{
$this->error = 'no_imagemagick_path';
return false;
@@ -139,7 +139,7 @@ class classImageImagemagick extends classImage implements interfaceImage
return false;
}
if( file_exists( $this->temp_file ) )
if( is_file( $this->temp_file ) )
{
@unlink( $this->temp_file );
}
@@ -164,12 +164,12 @@ class classImageImagemagick extends classImage implements interfaceImage
// Quality values
//---------------------------------------------------------
if( isset($opts['jpg_quality']) AND $opts['jpg_quality'] )
if( !empty($opts['jpg_quality']) )
{
$this->quality['jpg'] = $opts['jpg_quality'];
}
if( isset($opts['png_quality']) AND $opts['png_quality'] )
if( !empty($opts['png_quality']) )
{
$this->quality['png'] = $opts['png_quality'];
}
@@ -186,6 +186,71 @@ class classImageImagemagick extends classImage implements interfaceImage
return true;
}
/**
* Resizes and image, then crops an image to a fixed ratio
*
* @access public
* @param int Width of final cropped image
* @param int Height of final cropped image
*
*/
public function croppedResize( $width, $height )
{
/* Changes here made to prevent "division by 0" errors when getimagesize() failed */
$ratioOrig = $this->orig_dimensions['width'] / ( $this->orig_dimensions['height'] ? $this->orig_dimensions['height'] : 1 );
if( $ratioOrig < 1 )
{
$ratioOrig = 1;
}
if ( $width / $height > $ratioOrig )
{
$nheight = $width / $ratioOrig;
$nwidth = $width;
}
else
{
$nwidth = $height * $ratioOrig;
$nheight = $height;
}
$vals = $this->resizeImage( $nwidth, $nheight );
/* Crop from center */
$_x = $vals['newWidth'] / 2;
$_y = $vals['newHeight'] / 2;
$this->_cropX = ( $_x - ( $width / 2 ) );
$this->_cropY = ( $_y - ( $height / 2 ) );
$this->cur_dimensions['width'] = $width;
$this->cur_dimensions['height'] = $height;
return $this->resizeImage( $width, $height, true );
}
/**
* Crops an image
*
* @access public
* @param int Crop from X
* @param int Crop from Y
* @param int Width
* @param int Height
*
*/
public function crop( $x1, $y1, $width, $height )
{
$this->_cropX = $x1;
$this->_cropY = $y1;
$this->cur_dimensions['width'] = $width;
$this->cur_dimensions['height'] = $height;
return $this->resizeImage( $width, $height, true );
}
/**
* Resize image proportionately
*
@@ -243,7 +308,7 @@ class classImageImagemagick extends classImage implements interfaceImage
// Successful?
//---------------------------------------------------------
if( file_exists( $this->temp_file ) )
if( is_file( $this->temp_file ) )
{
return array( 'originalWidth' => $this->orig_dimensions['width'],
'originalHeight' => $this->orig_dimensions['height'],
@@ -252,7 +317,7 @@ class classImageImagemagick extends classImage implements interfaceImage
}
else
{
return array();
return array();
}
}
@@ -263,24 +328,24 @@ class classImageImagemagick extends classImage implements interfaceImage
* @param string File location (including file name)
* @return boolean File write successful
*/
public function writeImage( $path )
public function writeImage( $imagePath )
{
//---------------------------------------------------------
// Remove image if it exists
//---------------------------------------------------------
if( file_exists( $path ) )
if( is_file( $imagePath ) )
{
@unlink( $path );
@unlink( $imagePath );
}
//---------------------------------------------------------
// Temp file doesn't exist
//---------------------------------------------------------
if( !file_exists( $this->temp_file ) )
if( !is_file( $this->temp_file ) )
{
$this->error = 'temp_image_not_exists';
$this->error = 'temp_image_not_exists';
return false;
}
@@ -288,11 +353,11 @@ class classImageImagemagick extends classImage implements interfaceImage
// Rename temp file to final destination
//---------------------------------------------------------
rename( $this->temp_file, $path );
rename( $this->temp_file, $imagePath );
if( !file_exists( $path ) )
if( !is_file( $imagePath ) )
{
$this->error = 'unable_to_write_image';
$this->error = 'unable_to_write_image';
return false;
}
@@ -300,7 +365,7 @@ class classImageImagemagick extends classImage implements interfaceImage
// Chmod 777 and return
//---------------------------------------------------------
@chmod( $path, 0777 );
@chmod( $imagePath, IPS_FILE_PERMISSION );
return true;
}
@@ -309,7 +374,7 @@ class classImageImagemagick extends classImage implements interfaceImage
* Print image to screen
*
* @access public
* @return void Image printed and script exits
* @return @e void Image printed and script exits
*/
public function displayImage()
{
@@ -385,7 +450,7 @@ class classImageImagemagick extends classImage implements interfaceImage
// Working with original file or temp file?
//---------------------------------------------------------
$file = file_exists( $this->temp_file ) ? $this->temp_file : $this->image_full;
$file = is_file( $this->temp_file ) ? $this->temp_file : $this->image_full;
//---------------------------------------------------------
// Apply watermark and verify
@@ -393,7 +458,7 @@ class classImageImagemagick extends classImage implements interfaceImage
system("{$this->im_path}/composite -geometry +{$locate_x}+{$locate_y} {$path} {$file} {$this->temp_file}" );
if( file_exists( $this->temp_file ) )
if( is_file( $this->temp_file ) )
{
$this->force_resize = true;
@@ -446,7 +511,7 @@ class classImageImagemagick extends classImage implements interfaceImage
// Working with orig file or temp file?
//---------------------------------------------------------
$file = file_exists( $this->temp_file ) ? $this->temp_file : $this->image_full;
$file = is_file( $this->temp_file ) ? $this->temp_file : $this->image_full;
//---------------------------------------------------------
// Set gravity (location of text)
@@ -487,7 +552,7 @@ class classImageImagemagick extends classImage implements interfaceImage
system("{$this->im_path}/composite {$file} -fill {$color} -undercolor #000000 -gravity {$gravity} -annotate +0+5 '{$text}' {$this->temp_file}" );
if( file_exists( $this->temp_file ) )
if( is_file( $this->temp_file ) )
{
$this->force_resize = true;
@@ -503,7 +568,7 @@ class classImageImagemagick extends classImage implements interfaceImage
* Image handler desctructor
*
* @access public
* @return void
* @return @e void
*/
public function __destruct()
{
@@ -511,7 +576,7 @@ class classImageImagemagick extends classImage implements interfaceImage
// Remove temp file if it hasn't been saved
//---------------------------------------------------------
if( file_exists( $this->temp_file ) )
if( is_file( $this->temp_file ) )
{
@unlink( $this->temp_file );
}
@@ -519,4 +584,4 @@ class classImageImagemagick extends classImage implements interfaceImage
parent::__destruct();
}
}
}