PHP GD - Align text center-horizontally and decrease font size to keep it inside the image

前端 未结 2 1061
长情又很酷
长情又很酷 2021-02-10 01:58

Hope you are doing great.

I’m still a newbie with php so after making some reading and while checking some posts here I was able to put some text over an image with the

2条回答
  •  既然无缘
    2021-02-10 02:37

    You can use stil/gd-text class to align the text. Disclaimer: I am the author.

    setFontSize(75);
    $textbox->setFontFace('fabian.TTF');
    $textbox->setFontColor(new Color(255, 255, 255));
    $textbox->setBox(
        50,  // distance from left edge
        50,  // distance from top edge
        200, // textbox width
        100  // textbox height
    );
    
    // text will be aligned inside textbox to center horizontally and to top vertically
    $textbox->setTextAlign('center', 'top');
    $textbox->draw(strtoupper($nombre));
    

    However it is not a complete answer, because it can't decrease font size automatically.

提交回复
热议问题