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

Multiple Line Breaks & Detecting Rollover #370

Closed
FireController1847 opened this issue Nov 30, 2017 · 9 comments
Closed

Multiple Line Breaks & Detecting Rollover #370

FireController1847 opened this issue Nov 30, 2017 · 9 comments

Comments

@FireController1847
Copy link

FireController1847 commented Nov 30, 2017

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.

@ghost
Copy link

ghost commented Mar 6, 2018

It seems Jimp is very common with people using Discord.js.

To address the issue here you're placing the test in an absolute location. It doesn't know there is text already there as it is now literally pixels.

@FireController1847
Copy link
Author

That makes sense, but would it be possible to have something that, say, detected how long the text would be (in pixels), and then rollover if a word/letter goes past the specified size?

@ghost
Copy link

ghost commented Mar 7, 2018

IT does do that, hence the rollover in the first place. You're defining the position of the second text with an X value, and if it decided arbitrarily to put something NOT where you said to put it, it's unreliable.

@ghost
Copy link

ghost commented Mar 29, 2018

(close this please)

@FireController1847
Copy link
Author

When I was using the module, and I put a single line of text, it did not roll over and instead went off the side of the image.

@hipstersmoothie
Copy link
Collaborator

@FireController1847 can you provide an example of putting all the text in one line and it going off the screen? Line wrapping seems to be working in your above example.

@hipstersmoothie
Copy link
Collaborator

Closing:

@FireController1847
Copy link
Author

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

@hipstersmoothie hipstersmoothie moved this from Todo to Done in Better Font Support Aug 15, 2018
@johnxy84
Copy link

I have an issue with the text wrapping not still working with latest jimp version. I have an open issue here,
#710 but no feedback on it yet

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

No branches or pull requests

3 participants