imagemagick - More Efficient Method for PHP Imagick Color Replacement In PNG-24 -


i'm creating little web app people can choose colors different parts of race car. i'm using imagemagick take separate images of each part of car, recolor them (with clutimage function), , layer them on top of each other create final image.

each image png-24 alpha transparency. each image same size make easier combine them.

there ten layers, 6 of being recolored. problem performance bit poor; takes ten seconds render image after each color change. here's code:

sample code:

<?php   if(isset($piece['color'])) {      //make 1pixel image replace color      $clut = new imagick();      $clut->newimage(1, 1, new imagickpixel("#".$piece["color"]));      //change color of part      $car_part->clutimage($clut);   }   //now need add part onto car    $car->compositeimage($car_part, imagick::composite_default, 0, 0); 

clutimage seems might overkill task; i'm not doing gradient map, i'm replacing colored pixels solid color. yet no matter function use, still have iterate on several million pixels total.

is there more efficient way accomplish this, or nature of i'm trying do?

afaik, nature of doing. when comes down it, changing values of bunch of indices of multidimensional array. @ point or another, there loop.

there colorfloodfillimage, have never used method. may worth shot though.

i guess clutimage better iterating through pixels, because running @ c speeds, iterating through pixels using php construct (for/while/foreach) slower.

one way may able increase performance cache parts, given part x given color y generated once. next time wants paint part x color y, have pull rendered image cache. either store image file, or store imagick object in memory object cache (apc/memcached/etc.) right after clutimage call, can composite other objects.

hth.


Comments

Popular posts from this blog

python - Scipy curvefit RuntimeError:Optimal parameters not found: Number of calls to function has reached maxfev = 1000 -

c# - How to add a new treeview at the selected node? -

java - netbeans "Please wait - classpath scanning in progress..." -