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.

color for new image background is behaving weird

See original GitHub issue

First of all i want to say that Jimp is awesome really its much needed addition to nodejs libs 👍 but i having a little confusion that when i create a new image

var jimp = new Jimp(1200, 600, 0x00FF0000, cb);,

and i want to set image background i had to pass javascript octa numerals i want to ask is there any way to pass color string or hex code? if not then it would be awesome for future releases!

and weird thing is if i try to pass let suppose pink color

as Pink hex is ffc0cb i pass 0xFFffc0cb

but its giving me yellowish color!! may be i dont know how it works so its happening so kindly help 😃 thanks

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:5

github_iconTop GitHub Comments

2reactions
iwsfgcommented, Nov 19, 2016

Hi.

It’s RGBA, not ARGB, so your code should look like this

var img = new Jimp(1200, 600, 0xFFC0CBFF);

If you want to use strings with HEX codes, rgb()/rgba()/hsl()/hsla()/hsv() notations or literals like “crimson”, “gold”, etc. I would suggest using “tinycolor2” module. My helper function looks something like this:

var TinyColor = require('tinycolor2');

function arbitraryColorToInt (val) {
    val = val || 0; // 0, null, undefined, NaN

    if (typeof val === 'number') 
        return Number(val);

    var color = new TinyColor(val);
    return parseInt(color.toHex8(), 16);
}
0reactions
maqboolkhancommented, Jan 29, 2017

Thank you so much @Iwasawafag i just cant thank u 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why Placed Color Images Can Appear Inconsistent
You place two images that have identical colors in them… but they look different! This can drive you crazy. While there are a...
Read more >
An image and its background become yellow in Windows ...
When you view an image in Windows Photo Gallery in Windows Vista, the color of the image and its background become yellow.
Read more >
background-image acting weird - CSS Creator
Hi guys, I have some strange issue with the "background-image" property, ... width: 80%; background-color: lime; display: -webkit-box; ...
Read more >
Weird color distortion when using an effect on top of an ...
I later found that if I applied any effect to an element on top of my pink background, the pink changes from "bright...
Read more >
Why can't I use background image and color together?
You set the background-color and background-image styles. If the image is smaller than the element, you need to use the background-position ...
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