jeudi 30 juin 2016

Imagick CompositeImage feezes when destination is a bit out of the source

I'm trying to overlay a background image with many little icons. Sometimes, one of them goes over the edges of the background image, and this seems to make Imagick freeze. (The image generation takes a loooong time and at the end no image is rendered.)

Is that normal ?

I have ImageMagick 6.9.3-7 Q16 x68 and PHP 5.5.12.

Thanks for your help !

Here is the function that displays icons :

It's a PHP script with Imagick. Here it is.

public function render($imagick, &$draw, &$cursor, &$ready2Print){
    //var_dump($this);
    $metrics = $ready2Print->getCharMetrics();
    //var_dump($metrics);
    $tmpcur = [
        'x' => 0,
        'y' => 0
    ];
    foreach($this->_manas as $mana){
        //if(!self::isExistingMana($mana)) continue;
        // On charge le fichier
        $manaImage = new Imagick(self::getManaFile($mana));
        $size = 0; $yoffset = 0; $xoffset = 0; $advance = 0;
        if($manaImage->getNumberImages() == 0) continue;

        if(self::isLargeMana($mana)){
            // Rendu mana large
            $size = (int)($metrics['characterHeight'] * self::LARGE_MANA_RATIO);
            //var_dump($size);
            $manaImage->resizeImage(0, $size, Imagick::FILTER_LANCZOS, 1);
            $yoffset = (int)($metrics['characterHeight'] * self::LARGE_MANA_TOPLINE);
            $xoffset = (int)($metrics['characterHeight'] * ( self::LARGE_MANA_EFFECTIVE_WIDTH - self::LARGE_MANA_RATIO) / 2);
            $advance = (int)($metrics['characterHeight'] * self::LARGE_MANA_EFFECTIVE_WIDTH);
        } else {
            // Rendu mana small
            $size = (int)($metrics['characterHeight'] * self::SMALL_MANA_RATIO);
            //var_dump($size);
            $manaImage->resizeImage(0, $size, Imagick::FILTER_LANCZOS, 1);
            $yoffset = (int)($metrics['characterHeight'] * self::SMALL_MANA_TOPLINE);
            $xoffset = (int)($metrics['characterHeight'] * ( self::SMALL_MANA_EFFECTIVE_WIDTH - self::SMALL_MANA_RATIO) / 2);
            $advance = (int)($metrics['characterHeight'] * self::SMALL_MANA_EFFECTIVE_WIDTH);
        }

        $imagick->compositeImage(
            $manaImage, Imagick::COMPOSITE_OVER,
            $cursor->x + $tmpcur['x'] + $xoffset,
            $cursor->y + $tmpcur['y'] - $yoffset
        );
        $tmpcur['x'] += $advance;
    }
}

It's a simple loop with coordinates calculations and a CompositeImage call.

Aucun commentaire:

Enregistrer un commentaire