I've been working on a bigger app that pack 3D models together in nodeJS, and notice something I bumped into something I cannot resolve after hours of researches.
I did manage to get my basic problem into a few line of code.
import Sharp from 'sharp'
async function process(){
var sharpOriginal = Sharp('./samples/checker.jpg')
const sharpNew = Sharp({
create: {
width: 100,
height: 100,
channels: 3,
background: { r: 255, g: 255, b: 255 }
}
})
var op = {
input: await sharpOriginal.toBuffer(),
left: 0,
top: 0,
width: 100,
height: 100
}
var extractedImage = sharpOriginal.extract( op )
extractedImage.jpeg({quality:100})
var composite = [
{
input: await extractedImage.toBuffer(),
left: 0,
top: 0
}
]
sharpNew.composite(composite).jpeg({quality:100}).toFile('./samples/extract.jpg')
}
process()
Basically, using sharp, https://www.npmjs.com/package/sharp, v0.33.2
1 ) Importing an image
2 ) extracting a portion into another one
3 ) Compositing it into a new one, and save it, leads to color changes. I'm using a basic UV-checker jpg :
There is the result :
Using gimp to compare colors :
Original color : bcd300
Extracted color : c6c724
We can also notice a neat color difference between left : extracted / right : original
Is there a way to get all those operation without altering any of the color informations ?





