Skip to content

Commit

Permalink
Fixed issue with ImageMagick 6.7.5+
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffturcotte committed Jan 9, 2014
1 parent c739f22 commit 2574fa9
Showing 1 changed file with 25 additions and 5 deletions.
30 changes: 25 additions & 5 deletions fImage.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
* @package Flourish
* @link http://flourishlib.com/fImage
*
* @version 1.0.0b34
* @version 1.0.0b35
* @changes 1.0.0b35 Fixed an issue with ImageMagick 6.7.5+ and colorspace argument [jt, 2014-01-09]
* @changes 1.0.0b34 Fixed a bug in getImageType() where the fread was not reading enough bytes [jt, 2012-06-05]
* @changes 1.0.0b33 Fixed a method signature [wb, 2011-08-24]
* @changes 1.0.0b32 Added a call to clearstatcache() to ::saveChanges() to solve a bug when fFile::output() is called in the same script execution [wb, 2011-05-23]
Expand Down Expand Up @@ -72,6 +73,13 @@ class fImage extends fFile
*/
static private $imagemagick_temp_dir = NULL;

/**
* The version of ImageMagick
*
* @var string
*/
static private $imagemagick_version = NULL;

/**
* The processor to use for the image manipulation
*
Expand All @@ -96,10 +104,12 @@ static private function checkImageMagickBinary($path)
);
}

$binary = $path . (fCore::checkOS('windows') ? 'convert.exe' : 'convert');

if (self::isOpenBaseDirRestricted($path)) {
exec($path . 'convert -version', $executable);
exec($binary . ' -version', $executable);
} else {
$executable = is_executable($path . (fCore::checkOS('windows') ? 'convert.exe' : 'convert'));
$executable = is_executable($binary);
}

if (!$executable) {
Expand All @@ -108,6 +118,12 @@ static private function checkImageMagickBinary($path)
$path
);
}

// determine version
exec($binary, $output);
if (preg_match('/\d+\.\d+\.\d+/', $output[0], $matches)) {
self::$imagemagick_version = $matches[0];
}
}


Expand Down Expand Up @@ -159,7 +175,7 @@ static public function create($file_path, $contents)
*
* @return void
*/
static private function determineProcessor()
static public function determineProcessor()
{
// Determine what processor to use
if (self::$processor === NULL) {
Expand Down Expand Up @@ -1182,7 +1198,11 @@ private function processWithImageMagick($output_file, $jpeg_quality)

// Default to the RGB colorspace
if (strpos($command_line, ' -colorspace ') === FALSE) {
$command_line .= ' -colorspace RGB ';
if (version_compare(self::$imagemagick_version, '6.7.5') >= 0) {
$command_line .= ' -colorspace sRGB ';
} else {
$command_line .= ' -colorspace RGB ';
}
}

if ($new_type == 'jpg') {
Expand Down

0 comments on commit 2574fa9

Please sign in to comment.