我遇到了ImageIck PHP CLASS的问题。我的提供者(1und1.de)只允许通过ImageIck通过convert-CMD编辑图像。我有一个脚本,我在另一台服务器上使用不同的提供程序,允许安装ImageIck CLASS。
这是剧本:
header("Cache-Control: private, max-age=".(60 * 60 * 24 * 7).", pre-check=".(60 * 60 * 24 * 7));
header("Pragma: private");
header("Expires: " . date(DATE_RFC822,strtotime(" 2 day")));
$valid_size = array('xx','sm','xs'); //XX = 1440px * 960px // SM =
$img = $_GET['img'];
if(!empty($_GET['output-quality'])) $img_quality = $_GET['output-quality']; else $img_quality = NULL;
if(!empty($_GET['output-size']) && in_array($_GET['output-size'],$valid_size)) $img_size = $_GET['output-size']; else $img_size = NULL;
$img_arr = explode('.',$img);
$img_type = $img_arr[1];
$img_path = '../'.$img;
if(isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) && (strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE']) == filemtime($img_path))) {
header('Last-Modified: '.gmdate('D, d M Y H:i:s', filemtime($img_path)).' GMT', true, 304);
exit;
}
$im = new Imagick($img_path);
if(!is_null($img_quality)) $im -> setImageCompressionQuality($img_quality);
if(!is_null($img_size)) {
switch($img_size) {
case 'xx' :
$w = 1440;
$h = 940;
break;
case 'sm' :
$w = 300;
$h = 200;
break;
case 'xs' :
$w = 150;
$h = 150;
break;
}
$dim = $im -> getImageGeometry();
$wDim = $dim['width'];
$hDim = $dim['height'];
if($wDim >= 150 || $hDim >= 150) {
if($wDim >= $hDim) {
$o_scale = $wDim / $hDim;
$n_scale = $w / $h;
if($n_scale >= $o_scale) {
$im -> scaleImage($w,0);
} else $im -> scaleImage(0,$h);
} else {
$o_scale = $hDim / $wDim;
$n_scale = $w / $h;
if($n_scale >= $o_scale) {
$im -> scaleImage($w,0);
} else $im -> scaleImage($w,0);
}
$dim = $im -> getImageGeometry();
$wDim = $dim['width'];
$hDim = $dim['height'];
$wTemp = ($wDim - $w) / 2;
$hTemp = ($hDim - $h) / 2;
$im -> cropImage($w,$h,$wTemp,$hTemp);
}
}
header('Content-type: image/'.$im -> getImageFormat());
header('Content-disposition: inline; filename="'.$img.'"');
echo $im;
对于ImageIck CLASS,这对我来说很好用,但现在我必须使用convert-CMD来处理没有ImageIck CLASS的处理。 我不知道如何应对这个命令行工具......
谢谢!