php – 用imagemagick创建图片太慢了.如何提高?
我正在编写一个小CMS,你可以上传几个图像.
这些图像通过imagemagick转换为3个版本(大,中和缩略图大小). 问题是imagemagick需要5分钟才能创建4张图片的3个版本(已上传). 这是imagemagick命令的部分: foreach($upIMGS as $key => $filename){ list($width,$height) = getimagesize($path.$filename); if ($width > $height) $size = "x96"; else $size = "96x"; exec(P_IMAGEMAGICK." ".$path.$filename." -resize $size -gravity center -crop 96x96+0+0 +repage ".$path."th-".$filename); exec(P_IMAGEMAGICK." ".$path.$filename." -resize 320x320 ".$path."hl-".$filename); exec(P_IMAGEMAGICK." ".$path.$filename." -resize 514x ".$path."fl-".$filename); unlink($path.$filename); } [$upIMGS是一个包含最近上传图像的所有文件名的数组] 我的意思是..它确实有效,但太慢了,5分钟后服务器给我一个错误.一些文件是生成的,有些不是…… 如果你能给我一个提示,那将是非常好的. 解决方法
我最近遇到了同样的问题,但我只是通过图像一次将它们从原来的2592×1944调整为300xbestFit或bestFitx300
我使用的是PHP类imagick而不是命令行,但是在我的情况下,通过更改为-scale或scaleImage,我将时间缩短了一半.这是我的测试代码的片段. while ($images = readdir($handle)) { // check to see if the first or second character is a '.' or '..',// if so then remove from list if (substr($images,1) != '.') { //Check files to see if there extensions match any of the following image extensions. // GLOB_BRACE looks for all glob criteria within the {braces} $images = glob($dir."{*.gif,*.jpg,*.png,*.jpeg}",GLOB_BRACE); // the glob function gives us an array of images $i = 0; foreach ($images as $image) { // parse the data given and remove the images/ $dir,// imagemagick will not take paths,only image names. $i++; list ($dir,$image) = split('[/]',$image); echo $i," ",$image,"<br />"; $magick = new Imagick($dir."/".$image); $imageprops = $magick->getImageGeometry(); if ($imageprops['width'] <= 300 && $imageprops['height'] <= 300) { // don't upscale } else { // 29 Images at 2592x1944 takes 11.555036068 seconds -> // output size = 300 x 255 $magick->scaleImage(300,300,true); // 29 Images at 2592x1944 takes 23.3927891254 seconds -> // output size = 300 x 255 //$magick->resizeImage(300,imagick::FILTER_LANCZOS,0.9,true); $magick->writeImage("thumb_".$image); } } } } 我正在2592×1944处理29张图像,从23.3927891254秒到11.555036068秒.我希望这有帮助. 编辑: 除了我上面所说的,我刚刚在ImageMagick v6 Examples — API & Scripting遇到了以下内容,这可能会有所帮助: >“Shell脚本本质上很慢.它被解释,需要 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |