question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Multiple Line Breaks & Detecting Rollover

See original GitHub issue

When creating a Jimp and adding text, I want to add multiple lines like so:

async function modifyImage() {
  const img = await global.jimp.read("red_black_bg.png");
  const font = await global.jimp.loadFont("font.fnt");
  img.print(font, 10, 380, 'I Know What You Did Last Summer', 1920); // text 1
  img.print(font, 10, 500, 'Shawn Mendes & Camila Cabello', 1920); // text 2
  img.getBuffer(global.jimp.MIME_PNG, function(err, buffer) {
    if (err) throw new Error(error);
    else m.channel.send({files: [buffer]});
  });
}

The issue is, when text 1 wraps, it overlaps with text 2. Is it possible to detect this at all? I’ve tried inserting line-breaks into the first text but that doesn’t seem to work.

Here’s an example:

async function modifyImage() {
  const img = await global.jimp.read("red_black_bg.png");
  const font = await global.jimp.loadFont("font.fnt");
  img.print(font, 10, 380, 'I Know What You Did Last Summer ABCDEFGHIJKLMNOP', 1920); // text 1
  img.print(font, 10, 500, 'Shawn Mendes & Camila Cabello', 1920); // text 2
  img.getBuffer(global.jimp.MIME_PNG, function(err, buffer) {
    if (err) throw new Error(error);
    else m.channel.send({files: [buffer]});
  });
}

In the example above, the “ABCDEFGHIJKLMNOP” overlaps the text 2 as seen in the result:

I’ve pulled this off using Node.js v9.2.0 using npm 5.5.1. I don’t know any other languages so… that’s all I can give you.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:9

github_iconTop GitHub Comments

1reaction
FireController1847commented, Aug 12, 2018

apologies for not responding, honestly it’s been so long I forgot about the issue and I’m not even attempting this anymore lol

0reactions
johnxy84commented, Mar 17, 2019

I have an issue with the text wrapping not still working with latest jimp version. I have an open issue here, https://github.com/oliver-moran/jimp/issues/710 but no feedback on it yet

Read more comments on GitHub >

github_iconTop Results From Across the Web

How can I do a line break (line continuation) in Python?
Long lines can be broken over multiple lines by wrapping expressions in parentheses. These should be used in preference to using a backslash...
Read more >
Use Line Breaks, Paragraph Ends, and Tabs ...
When including literal text strings in computation scripts, you can have HotDocs merge line breaks, paragraph ends, and tabs in the answer.
Read more >
How can I handle the millis() rollover?
Short answer: do not try to “handle” the millis rollover, write rollover-safe code instead. Your example code from the tutorial is fine.
Read more >
Identifying Head-and-Shoulders Patterns in Stock Charts
Identifying so-called head-and-shoulders patterns can be tricky but profitable. ... head-and-shoulder when the stock breaks higher through the neckline.
Read more >
Cluster fault detection | Elasticsearch Guide [8.5]
When a node leaves the cluster, logs for the elected master include a message like this (with line breaks added for clarity):.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found