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

Font Kerning #77

Open
vicjalan opened this issue Jun 10, 2015 · 5 comments
Open

Font Kerning #77

vicjalan opened this issue Jun 10, 2015 · 5 comments

Comments

@vicjalan
Copy link

Hi,

I didn't see any option of adjusting letter spacing(font kerning). This is a great fun library to use and it's the one thing that is missing for the projects I am working on. Is there a workaround to this?

Thanks

@jdecool
Copy link
Collaborator

jdecool commented Jun 10, 2015

Hi @vicjalan,

Actually it's not possible to set letter spacing, because of GD limitation.

I just try to make a workaround and add a $spacing parameter to ImageWorkshopLayer::write function.

I just push a "feature/font-spacing" branch.
If you want, feel free to give me a feedback.

@vicjalan
Copy link
Author

Hi jdecool,

Thanks for looking into this. I downloaded the updated code from the "feature/font-spacing" branch. I tried adding a value for the $spacing parameter but no matter the value I just get a black box around the text but no spacing is applied.

The line of code looks like(where 5 should be the value for $spacing):

$powerLayer = ImageWorkshop::initTextLayer('POWER', 'Resources\fonts\berlin-sans-fb-demi-bold.ttf', 23, 'ffffff', 0, 5);

spacing

Thanks again!

@vicjalan
Copy link
Author

Hi jdecool,

I understand what's happening now. The function initTextLayer doesn't have the $spacing parameter defined, the last parameter it has is $backgroundColor which is why the color was changing instead of adjusting the width.

I added the $spacing parameter to the initTextLayer function. However the dimensions of the text string is being looked up before the write function. So what this means is that the layer's width/height is being determined by the string length so when the letters are broken up and re-assembled with the spacing the text appears cut off.

I'm not sure if I'm explaining myself correctly but here is what I changed:

    public static function initTextLayer($text, $fontPath, $fontSize = 13, $fontColor = 'ffffff', $textRotation = 0, $backgroundColor = null, $spacing = 0)
    {
        $textDimensions = ImageWorkshopLib::getTextBoxDimension($fontSize, $textRotation, $fontPath, $text);

        $layer = static::initVirginLayer($textDimensions['width'], $textDimensions['height'], $backgroundColor);
        $layer->write($text, $fontPath, $fontSize, $fontColor, $textDimensions['left'], $textDimensions['top'], $textRotation, $spacing);

        return $layer;
    }

Also if I set any text rotation it looks like so
spacing_rotation

@jdecool
Copy link
Collaborator

jdecool commented Jun 11, 2015

Thanks for your feedback.

I just try to write a quick POC.

I'm going to continue this feature next week.

@mklahorst
Copy link

Just checking in on this to see letter spacing is now part of latest build.

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

No branches or pull requests

3 participants