I’ve created this imagick php code to create my own images in gif format. All the code is perfect except one thing. The last text (date) is overwriting the title text. Can someone figure this out?
The result for what i’ve build is like this
[![enter image description here][1]][1]
This is the code from that
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 );
As you can see that the date (’58 days ago’) is overwriting the text “PAYING” from the gif image
anyone can help me figure this out? thanks
Advertisement
Answer
Found the fix.!!
First we need to know the height of images then reverse the Y position
$imgHeight/1
and put in the correct position.