summaryrefslogtreecommitdiff
path: root/it.class
diff options
context:
space:
mode:
authorChristian Schneider2012-08-06 14:24:04 +0000
committerChristian Schneider2012-08-06 14:24:04 +0000
commita7b19afaf311ed1ad37596a6fe834f24d1fd3e38 (patch)
treeef9ee16995e16cfdae568c290576a1455cd1ea97 /it.class
parente0e06bcc5ea10ff5498a842a9e9eb5ddce46bca5 (diff)
downloaditools-a7b19afaf311ed1ad37596a6fe834f24d1fd3e38.tar.gz
itools-a7b19afaf311ed1ad37596a6fe834f24d1fd3e38.tar.bz2
itools-a7b19afaf311ed1ad37596a6fe834f24d1fd3e38.zip
add keepalpha option to it::imageconvert(), re-format source to better match itools standard
Diffstat (limited to 'it.class')
-rw-r--r--it.class38
1 files changed, 23 insertions, 15 deletions
diff --git a/it.class b/it.class
index 5b34188..4a5a939 100644
--- a/it.class
+++ b/it.class
@@ -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 === "";
}