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

How to overlayWith new sharp() then how to overlayWith text? #1263

Closed
Antecer opened this issue Jun 20, 2018 · 4 comments
Closed

How to overlayWith new sharp() then how to overlayWith text? #1263

Antecer opened this issue Jun 20, 2018 · 4 comments
Labels

Comments

@Antecer
Copy link

Antecer commented Jun 20, 2018

I find your sample code like this in #512 , but it do not work.
There is no text parameter here, it doesn't even exist in the API documentation

sharp(null, {
    text: {
        text: string,
        font: string,
        width: integer,
        align: string,
        dpi: integer,
        spacing: integer
    }
})...

And then i find another sample code in #470 , there is no create parameter in overlayWith.
But i can find the options.create in your API documentation

sharp('input.jpg')
  .overlayWith(null, create: {
    width: 16,
    height: 32,
    channels: 4,
    background: rgba
})

So, did I use the wrong version, or did these features have not yet been developed?
Is there another alternative here? I just want to add a layer of translucent foreground color to the picture and print some text on it.

@lovell
Copy link
Owner

lovell commented Jun 20, 2018

Hello, the API in #512 (comment) is proposed. Please see #512 for suggestions of using SVG as an alternative and subscribe to it for updates.

@Antecer
Copy link
Author

Antecer commented Jun 21, 2018

@lovell
Thanks for your help, i added the text successfully, but the new question appeared again.
this is my test code:

const titlebar = new Buffer.from(
    `<svg width="1366" height="768">
        <style>
            @font-face {
                font-family: Aller_Light;
                src: url(${Aller_Light_Path}) format('truetype');
            }
        </style>
        <rect x="0" y="0" width="1366" height="768" fill="#000" fill-opacity="0.4"/>
        <rect x="0" y="0" width="1366" height="96" fill="#000" fill-opacity="0.8"/>
        <text class="title" style="font-size: 24; font-family:Aller_Light" x="5" y="22" fill="#FFF">
            Hello World
        </text>
    </svg>`
);
sharp(Buffer.concat(imgArrayBuffer))
    .toFormat('jpeg')
    .overlayWith(titlebar)
    .toFile(recpath)
    .then(buf => {
        console.log(`[sharpOK]success!`);
    })
    .catch(err => {
        console.log(`[sharpErr]${err}`);
    });

I get this error:
(sharp:6632): Pango-WARNING **: couldn't load font "Aller_Light Not-Rotated 24", falling back to "Sans Not-Rotated 24", expect ugly output.

How can I successfully load the font?

@lovell
Copy link
Owner

lovell commented Jun 21, 2018

Please see #1162

@Antecer
Copy link
Author

Antecer commented Jun 21, 2018

@lovell
Sorry, that doesn't seem to help, because I developed on win10 and then deployed to Heroku.
How do I customize the Fonts folder?

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

No branches or pull requests

2 participants