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

Text center not working for rasterized image #111

Open
notflip opened this issue Nov 7, 2020 · 4 comments
Open

Text center not working for rasterized image #111

notflip opened this issue Nov 7, 2020 · 4 comments
Labels
feature New feature or request

Comments

@notflip
Copy link

notflip commented Nov 7, 2020

I'm using the following code to rasterize an SVG image that has text

image

This is my code

        $image = new SVG(280, 280);
        $doc = $image->getDocument();

        $background = new SVGRect(0, 0, 280, 280);
        $background->setStyle('fill', '#ff4444');
        $doc->addChild($background);

        $text = (new SVGText($initials, '50%', '50%'))
            ->setFont(new SVGFont('Raleway', 'fonts/raleway.ttf'))
            ->setSize(120);

        $text->setStyle('line-height', 1);
        $text->setAttribute('text-anchor', 'middle');
        $text->setAttribute('alignment-baseline', 'middle');

        $doc->addChild($text);

I'm using 50% for the SVG text but it seems like the left bottom bounding box point is being used, instead of the center of the text node. Am I missing something?

Could it be that the following properties are ignored by the rasterize method?

$text->setAttribute('text-anchor', 'middle');
$text->setAttribute('alignment-baseline', 'middle');

Thank you!

@notflip notflip changed the title Text position and size different for SVG vs Rasterized Text center not working for rasterized image Nov 7, 2020
@meyfa
Copy link
Owner

meyfa commented Dec 4, 2020

text-anchor added via #97. alignment-baseline still pending.

@meyfa meyfa added the feature New feature or request label Dec 4, 2020
@bogart0324
Copy link

hi, beside from this setFont(new SVGFont('Raleway', 'fonts/raleway.ttf')), what else need to do to make the font working? I tried it but seem the correct font is not applied.

@notflip
Copy link
Author

notflip commented Dec 7, 2020

@bogart0324 It's probably in the wrong folder? My fonts folder is located in my public folder, from which my php script (index.php) is being ran.

@bogart0324
Copy link

bogart0324 commented Dec 7, 2020 via email

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

No branches or pull requests

3 participants