Automattic / Automattic/node-canvas

Unable to load custom font

Open
#1,600 3 comments 2 reactions 0 assignees View on GitHub
Text & Fonts
Dominant language
JavaScript
Stars
10.7k
Forks
1.2k
Avg merge
4d 8h
Merged PRs (30d)
1

Description

## Issue or Feature

## Steps to Reproduc
```

## Your Environment
* Version of node-canvas (output of `npm list canvas` or `yarn list canvas`):
* Environment (e.g. node 4.2.0 on Mac OS X 10.8):

const { createCanvas, Image, registerFont } = require('canvas');
const Canvas=require('canvas');
var fs = require('fs')
var path = require('path')
const express = require('express');
const app = express();
app.get('/font/:font', async function (req, res) {
Canvas.registerFont('./font/NotoSansHans-Bold.ttf', { family: 'Noto Sans S Chinese Bold' })
const canvas = createCanvas(400, 400)
const ctx = canvas.getContext('2d')
const font=req.params.font;
ctx.font = "280px Noto Sans S Chinese Bold"
ctx.fillStyle="#fff"
ctx.fillText((font), 70, 400-100)
console.log(font)
let out=fs.createWriteStream(path.join(__dirname, "/i/"+font+'.png'))
canvas.createPNGStream().pipe(out)
out.on('finish', () => {
res.end('make ok')
console.log('The PNG file was created.')
})
});
app.listen(3200, function () {
console.log('Example app listening on port 3200!');
});

$ node test.js
Example app listening on port 3200!

(process:5400): Pango-WARNING **: 14:49:53.166: couldn't load font "Noto Sans S
Chinese Bold Not-Rotated 280px", falling back to "Sans Bold Not-Rotated 280px",
expect ugly output.

The PNG file was created.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.