用imagick将.psd和.ai转换为PNG / JPG [英] Convert .psd and .ai to PNG/JPG with imagick
本文介绍了用imagick将.psd和.ai转换为PNG / JPG的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在为数字资产管理器创建缩略图,使用imagemagick执行此操作的最佳方法是什么?
I'm creating thumbnails for a Digital asset manager, what is the best way to do this with imagemagick?
那里有很好的资源吗?
推荐答案
我解决了它并将与世界分享!它会将.ai,.psd,.jpg,.png,.gif转换为缩略图。
I solved it and will share with the WORLD! it will convert .ai, .psd, .jpg, .png, .gif into thumbnails.
这是一个需要4个参数的函数:
Here is a function that takes 4 params:
$ dir - 要保存的目录。
$ tmpName - 命名文件的名称,不包括扩展名。
$ fileType - self说明。
$尺寸 - 大或小。
$dir - directory to save to.
$tmpName - the name to name the file excluding the extension.
$fileType - self explanatory.
$size - Large or small.
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);;
}
}
这篇关于用imagick将.psd和.ai转换为PNG / JPG的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文