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

tint() results in wrong colors #3506

Closed
higoka opened this issue Dec 27, 2022 · 2 comments
Closed

tint() results in wrong colors #3506

higoka opened this issue Dec 27, 2022 · 2 comments
Labels

Comments

@higoka
Copy link

higoka commented Dec 27, 2022

Im trying to overlay a color over an image. I know there is the tint() function but it results in wrong colors.

I have this base image i want to colorize with the hex color #ffc680.

Base Image

This is my code:

await sharp('base.png')
  .tint({ r: 255, g: 198, b: 128 }) // #ffc680
  .toFile('result.png')

Result:

Bad Image

Expected:

Good Image

As you can see the colors are lighter than the expected result. Does anybody have a solution to this?

I also tried using Jimp and can create a correct image using Jimp's color filter: https://github.com/oliver-moran/jimp/tree/master/packages/plugin-color#color

const baseImage = await Jimp.read('base.png')
const mask = baseImage.clone().color([
  { apply: 'mix', params: [ 'ffc680', 100 ] }
])

baseImage.composite(mask, 0, 0, { mode: Jimp.BLEND_MULTIPLY })
await baseImage.writeAsync('result.png')

Hope someone can help me.

@lovell
Copy link
Owner

lovell commented Dec 28, 2022

Hi, did you see #3338? It contains some discussion around ways to improve tint.

@lovell
Copy link
Owner

lovell commented Jan 24, 2023

Let's track this at #3338

@lovell lovell closed this as completed Jan 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants