Skip to content

ReferenceError: applyText is not defined #609

Answered by almostSouji
KaminoCodes asked this question in Q&A
Discussion options

You must be logged in to vote

applyText is a function we define in the respective guide section, if you get that error you skipped that part of the guide. https://discordjs.guide/popular-topics/canvas.html#adding-in-text

// Pass the entire Canvas object because you'll need to access its width, as well its context
const applyText = (canvas, text) => {
	const ctx = canvas.getContext('2d');

	// Declare a base size of the font
	let fontSize = 70;

	do {
		// Assign the font to the context and decrement it so it can be measured again
		ctx.font = `${fontSize -= 10}px sans-serif`;
		// Compare pixel width of the text to the canvas minus the approximate avatar size
	} while (ctx.measureText(text).width > canvas.width - 300);

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by almostSouji
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #608 on February 23, 2021 19:37.