Skip to content

Generation hangs with long titles #25

@cwhite92

Description

@cwhite92

Thank you for the package! I'm using it on my Jigsaw static site to generate OG images for blog posts, and seeing an issue with certain post titles.

The following snippet hangs indefinitely on my machine and pegs a PHP process at 100% CPU usage:

return (new Image())
    ->accentColor('#cc0000')
    ->border()
    ->url($item->getUrl())
    ->title('Adding Unique Field to MySQL Table With Existing Records')
    ->description('Test description')
    ->background(Background::JustWaves, 0.2)
    ->toString();

Shortening the title to:

->title('Adding Unique Field to MySQL')

generates the image almost instantly.

Interestingly, it doesn't seem to just be an issue with title length, because this is successful:

->title('foo bar foo bar foo bar foo bar foo bar foo bar foo bar foo bar foo bar foo bar foo bar foo bar')

However, removing spaces causes the hanging issue:

->title('foobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobar')

I source dived a bit and think I tracked the problem down to the while() loop in getFinalTextBox() in the TextBox class. It seems to have an issue fitting this specific text in the text box and loops indefinitely.

I'm happy to prepare a PR to fix this, but the code around here is pretty complicated. If you could point me in the right directly perhaps I can understand it better and propose the correct fix?

Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions