0

I'm currently trying to create a meme website site, a problem I'm having is I can't get the code to work which should shrink the text when there's a large amount of characters. Can anyone point me in the direction or does anyone know why my text is not getting smaller when then wordcount increase.

As always thankyou for your help- much appreciated.

<?php

$color = new ImagickPixel('#ffffff');
$strokeSize = "2 : 2";
$text = "This is a load of text that should change in size when long.";
$fontsize ="55";



$draw = new ImagickDraw();
$outputImage = new Imagick('_img/user_memes/large/user_1/chicken.jpg');

// Get the width and height of the image
$imgSize   = $outputImage ->getImageGeometry();
$imgWidth  = $imgSize['width'];
$imgHeight = $imgSize['height'];

$draw->setFillColor('#fff');
$draw->setFont( "fonts/impact.ttf" );

$draw->setGravity(Imagick::GRAVITY_SOUTH);
$draw->setStrokeColor('#000');
$draw->setStrokeWidth(1);
$draw->setStrokeAntialias(true);
$draw->setTextAntialias(true);

// Set the desired width of the text to 90% of the image width
$textDesiredWidth = intval( $imgWidth * 0.9 );
$textDesiredHeight = intval( $imgHeight * 0.9 );
var_dump($outputImage->queryFontMetrics($draw, ''.$text.''));

// Create an array for the textwidth and textheight
$textProperties = array( 'textWidth' => 1 );


// Increase the fontsize until we have reached our desired width
while ( $textProperties['textWidth'] <= $textDesiredWidth ) {
$draw->setFontSize( $fontsize );
$textProperties = $outputImage->queryFontMetrics( $draw, $text );
$fontSize++;
}
echo "---" . $textProperties['textWidth'];

$outputImage->annotateImage($draw, 0, 5, 0, ''.$text.'');


$outputImage->setFormat('png');
$outputImage->writeimage('_img/user_memes/large/user_1/spork_thumbnail.png');

?>

<br><br>
<img src="_img/user_memes/large/user_1/spork_thumbnail.png" alt="some_text">
  • Is [this](http://stackoverflow.com/questions/7436815/php-imagick-how-to-best-fit-text-annotation) related? – msound Apr 21 '14 at 13:41
  • I think that's pretty much it- I'll give that ago tomorrow see how I get on. cheers buddy. – user3259342 Apr 21 '14 at 13:54
  • possible duplicate of [How can I draw wrapped text using Imagick in PHP?](http://stackoverflow.com/questions/5746537/how-can-i-draw-wrapped-text-using-imagick-in-php) – Danack May 04 '14 at 15:07

0 Answers0