0

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.

Thaledric
  • 539
  • 2
  • 8
  • 17
  • Posting your command may help as there may be a better method than the one you are using. If it is that which is causing a problem I would suggest calculating how many icons you can have in one row and using that in your code. – Bonzo Jun 26 '16 at 18:15
  • It's a PHP script with Imagick. Here it is. – Thaledric Jun 26 '16 at 18:28
  • Reducing the code to the simplest possible reproduce case would be a good idea. Without spending time investigating, it's hard to see what line is causing the problem. – Danack Jun 26 '16 at 19:58

0 Answers0