Jimp: color for new image background is behaving weird

Created on 18 Nov 2016  路  5Comments  路  Source: oliver-moran/jimp

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

question

Most helpful comment

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);
}

All 5 comments

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);
}

awesome will check when in home 馃憤

hey @Iwasawafag i passed #fff000 and it ruterns 255 i want to send it hex and then get RGBA which jimp can understand?

Perhaps you did something wrong. Here's the live demo: https://runkit.com/iwasawafag/588d0fc1a5de05001522146f

Thank you so much @Iwasawafag i just cant thank u :)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Inbarasan16 picture Inbarasan16  路  3Comments

dtrofimov picture dtrofimov  路  5Comments

slidenerd picture slidenerd  路  4Comments

fatihturgut picture fatihturgut  路  4Comments

Yimiprod picture Yimiprod  路  5Comments