做程序需要用到ImageMagick,于是就在网上下了安装文件
这里用的是ImageMagick-6.7.0-0-Q8-windows-dll,安装完成后,将安装路径写入PATH中(安装的最后一步可以选择自动添加)
在PHP的ext中将php_imagick_dyn-Q16.dll拖入,然后在PHP.ini中将扩展添加上去,重启Apache…
测试程序,谁知道没法切图
在命令行下执行:
“d:\Program Files\ImageMagick-6.7.0-Q8\convert.exe” d:\desktop\maoegg_big.jpg -gravity Center -resize 50×50 -crop 30×30 -strip +repage d:\maoegg_small.jpg
执行正常啊,将大图切成了几个小图
后来自己写了个测试页面:
$imagicPath = ‘”D:\\Program Files\\ImageMagick-6.7.0-Q8\\convert.exe”‘;
$imgOldPath = “D:\\desktop\\maoegg_big.jpg”;
$imgNewPath = “E:\\maoegg_small.jpg”;
exec($imagicPath .’ ‘. $imgOldPath.’ -gravity Center -resize 50×50 -crop 30×30 -strip +repage’. ‘ ‘.$imgNewPath);
结果报错:
Warning: exec() has been disabled for security reasons in
我晕,PHP没有执行权限。
修改PHP.ini,将“disable_functions = exec , popen, system …. ”中的exec给去掉。
再测试程序,还是不行…
echo $imagicPath .’ ‘. $imgOldPath. ‘ -gravity Center -resize 50×50 -crop 30×30 -strip +repage’. ‘ ‘.$imgNewPath;
结果是:
D:\Program Files\ImageMagick-6.7.0-Q8\convert.exe D:\desktop\maoegg_big.jpg -gravity Center -resize 50×50 -crop 30×30 -strip +repage E:\maoegg_small.jpg
然后将这句话复制到命令行再执行,结果出来了:
‘D:\Program’ 不是内部或外部命令,也不是可运行的程序或批处理文件
这个是路径中有空格导致的啊,因为程序在环境变量的PATH中添加了,后来将$imagicPath=”convert”;就搞定了
文章来源:毛蛋网(maoegg.com)




评论
发表评论 反向链接