Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Calculate font size automatically to fit a given box area #33

Open
tenq opened this issue Apr 20, 2020 · 4 comments
Open

Calculate font size automatically to fit a given box area #33

tenq opened this issue Apr 20, 2020 · 4 comments
Assignees
Labels

Comments

@tenq
Copy link

tenq commented Apr 20, 2020

Hi,

  1. have some example with form with image upload (blob without save, just use on memory) or image base64?

  2. If it's possible, how I do resize text to fit text (and resize font size) custom area?

@YeltsinReyes
Copy link

Hi,

  1. have some example with form with image upload (blob without save, just use on memory) or image base64?
  2. 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']);

@joseluisq
Copy link
Owner

joseluisq commented Apr 21, 2020

@tenq

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/

@tenq
Copy link
Author

tenq commented Jul 6, 2020

(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!

@joseluisq joseluisq self-assigned this Sep 22, 2020
@joseluisq joseluisq changed the title Question about images and text Calculate font size automatically to fit a given box area Sep 22, 2020
@joseluisq
Copy link
Owner

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants