我解决了它,并将与世界分享!它会将.ai,.psd,.jpg,.png,.gif转换为缩略图.
这是一个需要4个参数的函数:
$dir – 要保存的目录.
$tmpName – 命名不包括扩展名的文件的名称.
$fileType – 自解释.
$size – 大或小.
function thumbGenerator($dir,$tmpName,$fileType,$size){
$saveFileType = "png";
$imagePath = $dir.$tmpName.".".$fileType;
$image = new Imagick();
$image->readimage($imagePath);
if($fileType == "psd"){
$image->setIteratorIndex(0);
}
$dimensions = $image->getImageGeometry();
$width = $dimensions['width'];
$height = $dimensions['height'];
if($size == "large"){
$maxWidth = 720;
$maxHeight =720;
}
if($size == "small"){
$maxWidth = 250;
$maxHeight =250;
}
if($height > $width){
//Portrait
if($height > $maxHeight)
$image->thumbnailImage(0, $maxHeight);
$dimensions = $image->getImageGeometry();
if($dimensions['width'] > $maxWidth){
$image->thumbnailImage($maxWidth, 0);
}
}elseif($height < $width){
//Landscape
$image->thumbnailImage($maxWidth, 0);
}else{
//square
$image->thumbnailImage($maxWidth, 0);
}
if($size == "large"){
$image->writeImage($dir . $tmpName."-lg.".$saveFileType);
}
if($size == "small"){
$image->writeImage($dir . $tmpName."-sm.".$saveFileType);;
}
}