diff options
| -rw-r--r-- | it.class | 38 | 
1 files changed, 23 insertions, 15 deletions
| @@ -571,13 +571,14 @@ static function _exec_quotevalue($value, $errmsg = "")  /**   * Convert an image to a given size and type (ensures input is an image) - * @param $p['in']	Input filename (mandatory) - * @param $p['out']	Output filename (mandatory) - * @param $p['size']	Width x height of resulting image, e.g. "160x60" - * @param $p['type']	Output file type, e.g. "jpg" - * @param $p['types']	Comma separated list of accepted input types, default "bmp,eps,gif,jp2,jpg,png,svg,tif" - * @param $p['quality']	JPEG quality (0-100), default is 75 - * @param $p['-opts']	Custom command line options to ImageMagick convert + * @param $p['in']		Input filename (mandatory) + * @param $p['out']		Output filename (mandatory) + * @param $p['size']		Width x height of resulting image, e.g. "160x60" + * @param $p['type']		Output file type, e.g. "jpg" + * @param $p['types']		Comma separated list of accepted input types, default "bmp,eps,gif,jp2,jpg,png,svg,tif" + * @param $p['quality']		JPEG quality (0-100), default is 75 + * @param $p['keepalpha']	Don't add option --flatten to preserve alpha channel + * @param $p['-opts']		Custom command line options to ImageMagick convert   * @return Success of convert as true/false   */  static function imageconvert($p) @@ -591,25 +592,32 @@ static function imageconvert($p)  	}  	# emulate -auto-orient which is not supported by GM -	if ($p['-opts']['-auto-orient']) { +	if ($p['-opts']['-auto-orient']) +	{  		$exif = @exif_read_data($p['in'], 'IFD0'); -		switch ($exif['Orientation']) { -		case 2: $p['-opts']['-flop'] = true;  break; -		case 3: $p['-opts']['-rotate'] = 180; break; -		case 4: $p['-opts']['-flip'] = true;  break; -		case 6: $p['-opts']['-rotate'] = 90;  break; -		case 8: $p['-opts']['-rotate'] = 270; break; +		switch ($exif['Orientation']) +		{ +			case 2: $p['-opts']['-flop'] = true;  break; +			case 3: $p['-opts']['-rotate'] = 180; break; +			case 4: $p['-opts']['-flip'] = true;  break; +			case 6: $p['-opts']['-rotate'] = 90;  break; +			case 8: $p['-opts']['-rotate'] = 270; break;  		} +  		unset($p['-opts']['-auto-orient']);  	}  	$type = strtr($type, array("jpeg" => "jpg", "tiff" => "tif", "ps" => "eps", "ept" => "eps"));  	$p += array('type' => $type, 'types' => "bmp,eps,gif,jp2,jpg,png,svg,tif", 'quality' => 75);  	$p['-opts'] = array('-thumbnail' => $p['size'], '-quality' => $p['quality']) + (array)$p['-opts']; + +	if (!$p['keepalpha']) +		$p['-opts'] = array_merge(array('-flatten' => true), $p['-opts']);	# flatten must be first +  	$ultratimeout = file_exists("/opt/ultra/bin/ultratimeout") ? "/opt/ultra/bin/ultratimeout 30 " : "";  	if (in_array($type, explode(',', $p['types'])))	# Valid type? -		$cmdoutput = it::exec($ultratimeout . 'gm convert 2>&1 -flatten {-opts} {in} {type}:{out} || echo "SHELL ERROR $?"', $p); +		$cmdoutput = it::exec($ultratimeout . 'gm convert 2>&1 {-opts} {in} {type}:{out} || echo "SHELL ERROR $?"', $p);  	return $cmdoutput === "";  } |