1200字范文,内容丰富有趣,写作的好帮手!
1200字范文 > php对接ai图片处理 php – 使用imagick将.psd和.ai转换为PNG / JPG

php对接ai图片处理 php – 使用imagick将.psd和.ai转换为PNG / JPG

时间:2018-12-09 02:22:01

相关推荐

php对接ai图片处理 php – 使用imagick将.psd和.ai转换为PNG / JPG

我解决了它,并将与世界分享!它会将.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);;

}

}

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。