image icon indicating copy to clipboard operation
image copied to clipboard

The problem with the alignment of the text

Open cawa-93 opened this issue 10 years ago • 2 comments

    require_once 'vendor/autoload.php';
    use Intervention\Image\ImageManagerStatic as Image;

    $img = Image::make($_GET['backgroundsPath'].$_GET['backgroundFile']);

    $img->text($_GET['text'], 335, 175, function ($font) {
        $font->file('../fonts/intro-black-caps-webfont.woff');
        $font->size(34);
        $font->color("#ffffff");
        $font->align('center');
        $font->valign('top');
    });

2016-01-09 12 14 42 As can be seen in the image of the text in the middle position. But the text is not formatted correctly. How do I get something like this result? 2016-01-09 12 17 49

cawa-93 avatar Jan 09 '16 10:01 cawa-93

There is an issue with Intervention Image and GD library when writing multiline text. I suggest to use Intervention Image with Imagick driver for now.

olivervogel avatar Jan 09 '16 11:01 olivervogel

I am using Imagick and I am trying to align text vertically to middle and it is not working when text is multi line.

image

And with multi line text (same code):

image

$img->text($titles, 640, 360, function (Intervention\Image\Imagick\Font $font) {
        $font->file(storage_path('fonts/Roboto-Regular.ttf'));
        $font->size(22);
        $font->color('#ffffff');
        $font->align('center');
        $font->valign('middle');
    });

basepoint is exactly in center of the image. According to comments above this is supposed to work?

kovinet avatar Apr 13 '22 19:04 kovinet

reopening

omarshamali avatar Oct 23 '22 15:10 omarshamali

any solution for aligning center text over image ?

wyyr avatar Jun 07 '23 15:06 wyyr

Try to do something like this

//get image width and height
            $image_width = Image::make($image->getRealPath())->width() / 2;
            $image_height = Image::make($image->getRealPath())->height() / 2;

            Image::make($image->getRealPath())->text('Genzo Adam', $image_width , $image_height, function($font) {
                                                $font->file(storage_path().'/app/public/font/AppleTea-z8R1a.ttf');
                                                $font->size(50);
                                                $font->color('#f1f1f1');
                                                $font->align('center');
                                                $font->valign('middle');
                                            })->save($path, 50);

genzoadam avatar Sep 08 '23 19:09 genzoadam

I have this problem too, already try add align center and valign middle Screenshot 2023-09-20 at 11 02 43

putrafajarh avatar Sep 20 '23 04:09 putrafajarh

@putrafajarh have u tried width() / 2 & height() / 2 to get the real center pixel of your image? not just align/valign. check the code carefully on my last replay because ive done this issue with that.

genzoadam avatar Sep 20 '23 12:09 genzoadam

@genzoadam its not about centering the text vertically or horizontally, I want to the text-align to be centered, not align left. (2 line)

putrafajarh avatar Sep 20 '23 13:09 putrafajarh

I suggest to try this with version 3 of Intervention Image

olivervogel avatar Dec 08 '23 18:12 olivervogel