2012-10-30 63 views
0

我想實現this code snippet(一個 「小插曲」 效應)與Imagick,但處理是慢得令人難以置信:Imagick像素迭代器 - 很慢

set_time_limit(90); 
$iterator = $imagick->getPixelIterator(); 
$width = $imagick->getImageWidth(); 
$height = $imagick->getImageHeight(); 

foreach($iterator as $y => $pixels){ 
    foreach($pixels as $x => $pixel){ 

    $l = 1 - 0.7 * (1 - pow((sin(M_PI/$width * $x) * sin(M_PI/$height * $y)), 0.4));  

    extract($pixel->getColor()); 

    $pixel->setColor(sprintf('rgb(%d,%d,%d)', $r * $l, $g * $l, $b * $l)); 
    } 

    $iterator->syncIterator(); 
} 

原文:

enter image description here

結果:

enter image description here

對於1600x1200的圖像,要處理圖像需要35秒。有一個更好的方法嗎?

+0

對於涉及pow,sin,get和setColor的1920萬次操作,35秒35秒,我想Imagick做得很好。 –

+0

但與GD相同的效果應用更快與imagesetpixel,如12秒.. – thelolcat

回答

2

你所要做的是在殺ImageMagic已經-vignette命令

convert input.jpg -background black -vignette 70x80 output.png 

原始

enter image description here

最終輸出

enter image description here

+0

但這是可能的使用PHP函數?我嘗試vignetteImage(),但它將圖像變成一個橢圓與白色背景:) – thelolcat

+0

請參閱:http://eclecticdjs.com/mike/tutorials/php/imagemagick/examples_04/vignette.php – Baba