Skip to content

ImageMagick-style tint #3338

@shahkashani

Description

@shahkashani

Question about an existing feature

I'm pretty sure this is just me being stupid, but is there a way to use tint to achieve something like the below?

ImageMagick

convert "input.png" -fill "#c31306" -tint 100 "output.png"

output-im

Sharp

await sharp(image).tint('#c31306')

output-sharp

Note how the highs and lows are also tinted in the Sharp case, but not with ImageMagick.

The ImageMagick source code indicates that they use a weighting function for their tinting:

%  TintImage() applies a color vector to each pixel in the image.  The length
%  of the vector is 0 for black and white and at its maximum for the midtones.
%  The vector weighting function is f(x)=(1-(4.0*((x-0.5)*(x-0.5))))

But I am not sure how to convert this into Sharp terms. Perhaps I could use recomb somehow?

I have even tried to use composite, but none of the blend modes seem to be able to achieve what I want. multiply gets close, but I think ultimately what I need is something like Cairo's color blend mode, which doesn't exist in Sharp or vips.

Any help would be highly appreciated!

What are you trying to achieve?

A tint that preserves hights and lows.

When you searched for similar issues, what did you find that might be related?

I found some tickets regarding tint not behaving as expected, but those issues have been resolved.

Please provide a minimal, standalone code sample, without other dependencies, that demonstrates this question

const image = await sharp('input.png').toBuffer();
const outputBuffer = await sharp(image).tint('#c31306');
await outputBuffer.toFile('output.png');

Please provide sample image(s) that help explain this question

Raw image:

sandwich

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions