计算字体大小的数学公式

时间:2014-04-22 16:00:59

标签: math formula imagick

任何人都可以帮助我,我没有太多运气 我想根据文本覆盖的图像宽度和文本字符串中的字符数量,为我的文本尝试理想的字体大小。 任何人都可以帮我解决这个问题。

我让它半工作但只是因为无限猴子定理!

// gets text1 count 
$charcount = strlen($line1);
// gets text1 size from count
$newsize = ($width / floor($charcount));
$add = ( 20 % $newsize );
$newsize = ($newsize + $add);

// Changes Font Size
$text1->setFontSize( $newsize );

1 个答案:

答案 0 :(得分:0)

我根据图片的宽度或高度使用这样的东西:

 resize_font = function () {

   // then play around with the denominator until the font is the size you want 

var fontSize = parseInt($("#your_image_div").width()) / 2 + "%";



   //then apply that to your css for that text div element 

$(".your_text_class").css('font-size', fontsize);



};

        // then hook it to whatever event you want to 

        $(document).ready(resize);

希望这会有所帮助。这个技巧对于使元素与veiwport相关调整大小也很方便。希望能帮助到你。

相关问题