Imagick文本正在覆盖每帧

问题描述 投票:1回答:1

我创建了这个imagick php代码,以gif格式创建自己的图像。除了一件事,所有代码都是完美的。最后一个文本(日期)将覆盖标题文本。有人可以弄清楚吗?

我构建的结果是这样的

[![在此处输入图片描述] [1]] [1]

这是该代码

        ob_clean();
        $text=ucfirst('Title Name');
        $image = new Imagick('1.gif'); 

        $draw = new ImagickDraw(); 
        $frameCount = 0;
        foreach($image as $frame){
        $image->setImageDelay((($frameCount % 40) * 40));

        $draw->setGravity (Imagick::GRAVITY_NORTHWEST);
        $draw->setTextAlignment(Imagick::ALIGN_CENTER);

        $imgSize   = $image->getImageGeometry();
        $imgHeight = $imgSize['height']; 
        $imgWidth = $imgSize['width'];
        // Calculate size
        $textProperties = array( 'textWidth' => 0 );
        $textDesiredWidth = intval( $imgWidth * 0.9 );

        $defaultFontSize = 25;
        $fontSize = 0;
        $draw->setFillColor('white'); 
        /* Font properties */
        $draw->setFont('assets/fonts/EX.ttf'); 
        while ( $textProperties['textWidth'] <= $textDesiredWidth ) {
            $draw->setFontSize( $fontSize );
            $textProperties = $image->queryFontMetrics( $draw, $text );
            $fontSize++;
        }

        if($fontSize>$defaultFontSize){
            $draw->setFontSize( $defaultFontSize );
            $centerY = floor( ($imgHeight) / 3.3 );
        }else{
            $centerY = floor( ($imgHeight) / 3.6 );
        }
        $centerX = intval( ($imgWidth) / 2 );
        $image->annotateImage( $draw, $centerX, $centerY, 0, $text );

如您所见,日期('58天前)正在覆盖gif图片中的文本“ PAYING”

有人可以帮我解决这个问题吗?谢谢

php imagick
1个回答
0
投票

找到了补丁。!

首先我们需要知道图像的高度,然后反转Y位置

$imgHeight/1

并放在正确的位置。

© www.soinside.com 2019 - 2024. All rights reserved.