Calculate font size automatically to fit a given box area
tenq opened this issue · 4 comments
Hi,
-
have some example with form with image upload (blob without save, just use on memory) or image base64?
-
If it's possible, how I do resize text to fit text (and resize font size) custom area?
Hi,
- have some example with form with image upload (blob without save, just use on memory) or image base64?
- If it's possible, how I do resize text to fit text (and resize font size) custom area?
I'm sure you can do this.
$get = file_get_contents($_FILES['img']['tmp_name']);
1. have some example with form with image upload (blob without save, just use on memory) or image base64?
Can you clarify your question a bit? because I can not figure out what exactly is your requirement.
2. If it's possible, how I do resize text to fit text (and resize font size) custom area?
Here a simple explaination:
<?php
$text = new Text('My ustom text with opacity!');
$text
// these functions control the size of the text area (box area).
->setWidth(400)
->setHeight(250)
// these functions control the position (x, y) of the text area (box area).
->setLeft(50)
->setTop(50)
// this function controls the font size of the string text.
->setSize(22)
->setOpacity(0.5)
->setColor(255, 255, 255)
->setFontface('/home/my_user/fonts/Lato.ttf');
Check out the complete example at https://joseluisq.github.io/gimage/classes/text/
(Sorry for late response @joseluisq and @YeltsinReyes )
Thanks for the answers.
In my case, I have a space, say 200 x 50, when I write "Congratulations", it is displayed with a font size of 25px (example only), but if I want to write 'Congratulations, my dear friend ", how can I calculate dynamically the font size to use the same space (200x50)?
The same occurs when I have a space delimited for 2 lines, but I don't want to go beyond that and if the text is bigger, I would like to reduce the font so that it is possible to continue using only 2 lines ...
It's possible to make these calculations and resize dynamically?
thanks a lot!
What you want is calculate automatically the font size in a particular box area. That is not possible right now.
The library only takes the text with a given font size and then try to fit it into the box area (your canvas).
So that calculus is in your side for now. PR welcome.