我目前正在尝试创建一个meme网站,我遇到的问题是我无法使代码工作,这会导致文本大量缩小的人物。 任何人都可以指出我的方向,或者有人知道为什么我的文字在wordcount增加时不会变小。
总是谢谢你的帮助 - 非常感谢。
<?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">