You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Why does a sharp object not have persistence, I make a point to overlay each row of pixels and save the final image in the end but toFile() only creates an image with the last position I tried to overLay. Am I using overlayWith incorrectly or is that just the way it has been created. I cant find any information about this.
image.metadata().then((metadata) => {
return {
width: metadata.width,
height: metadata.height,
channels: metadata.channels
}
})
.then((metadata) => {
/*
** Tiles are 20x20 modulo for less computation
*/
var xMax = metadata.width - (metadata.width % 20)
var yMax = metadata.height - (metadata.height % 20)
let final = sharp({
create: {
width: xMax,
height: yMax,
channels: metadata.channels,
background: { r: 255, g: 255, b: 255 }
}
})
.jpeg()
/*
** Loop through x-axis
*/
for (let xOffset = 0; xOffset <= xMax; xOffset += 20)
{
/*
** Loop through y-axis
*/
for (let yOffset = 0; yOffset <= yMax; yOffset += 20)
{
/*
** To prevent a read biigger then possible
*/
if ((yOffset + 20) > metadata.height || (xOffset + 20) > metadata.width)
break ;
/*
** Extract the 20x20 tile from the input image
*/
image.clone().extract({
left: xOffset,
top: yOffset,
width: 20,
height: 20
})
.toBuffer()
.then((buffer) => {
/*
** Get the color distance of the 20x20 tile
*/
return color.distance(buffer)
.then((space) => { return space.space })
.catch((err) => console.log(err))
})
.then((space) => {
/*
** Find the image in the db with the smallest difference
*/
return distance.smallest(db, space)
})
.then((path) => {
/*
** Resize the image from the db with smallest difference
*/
return sharp(path).resize(20, 20).toBuffer()
})
.then((buffer) => {
/*
** Insert resized image into 20x20 tile
*/
final.overlayWith(buffer, {
top: yOffset,
left: xOffset
})
})
.catch((err) => console.log(err))
}
}
// final.toFile('./output/' + Date.now() + '.jpg')
})
.catch((err) => console.log(err))
The text was updated successfully, but these errors were encountered:
Why does a sharp object not have persistence, I make a point to overlay each row of pixels and save the final image in the end but toFile() only creates an image with the last position I tried to overLay. Am I using overlayWith incorrectly or is that just the way it has been created. I cant find any information about this.
The text was updated successfully, but these errors were encountered: