turakvlad / replace-color Goto Github PK
View Code? Open in Web Editor NEWReplace color with another one pixel by pixel.
License: MIT License
Replace color with another one pixel by pixel.
License: MIT License
Hey,
Great library.
I'm trying to remove the green from this image.
Here is my code
replaceColor({
image: dir + '/' + image.src,
colors: {
type: 'hex',
targetColor: '#00ff00',
replaceColor: '#00000000',
deltaE: 20
}
})
I'm still getting a green tinge around the letters.
Do you know how I can completely remove all the green?
Error shown as below
TypeError: Jimp.read is not a function
at eval (webpack:///./node_modules/replace-color/src/replace-color.js?:43:10)
at new Promise (<anonymous>)
at module.exports (webpack:///./node_modules/replace-color/src/replace-color.js?:20:10)
at IpcMainImpl.eval (webpack:///./src/background.js?:222:5)
And my code in the background.js
is
var replaceColor = require('replace-color')
replaceColor({
image: path_to_image,
colors: {
type: 'hex',
targetColor: targetColor,
replaceColor: '#00000000'
},
deltaE: 10
})
...
I trace the error message, and found the error is happened when reading the image.
which is in the node_modules/replace-color/src/replace-color.js
line 43
Jimp.read(image)
I tried many ways including add async await
stuff to make the process sync, but it is still not working.
Then no idea how to solve it.
Is possible to replace 2 or more colors ?
Hey guys, here we go again :)
The library is using jimp ^0.5.3
and not compatible with the latest jimp version I use in my project (0.6.4
). As last time, upgrading jimp here should do the trick :)
Affected by this lack of compatibility is my desire to composite
images that have been manipulated with replace-color
.
const transformedImage = await replaceColor({
image: imagePath,
colors: {
targetColor,
replaceColor: desiredColor,
type: 'hex'
}
})
Afterwards, when trying to someImage.composite(transformedImage, 0, 0)
I get the error message that transformedImage
is not a valid jimp object.
Looking forward to the fix!
Janik
It would be useful to return something other than a jimp object, such that I could call replaceColor
with a Buffer and receive a Buffer back.
Happy to write a PR if it would be welcomed. All it would require is potentially a new return type param and if buffer calling the jimp getBuffer
.
Can a replace color with a picture?
Hey guys,
I've been trying to replace colors for an image using this library and then using jimp (0.5.3
) to composite different images together.
my code:
const transformedImage = await replaceColor({
image: jimpObject | imagePath,
colors: {
targetColor,
replaceColor: desiredColor,
type: 'hex'
}
})
I encountered two errors:
When the image
parameter was the path to the image, transforming worked, but in the step where I did someJimpInstance.composite(transformedImage)
, jimp
was complaining that transformedImage
wasn't a valid jimp instance, even though the instanceof Jimp
test was true.
When using a jimpObject
as a value for the image
parameter, replaceColor
threw this error: No matching constructor overloading was found. Please see the docs for how to call the Jimp constructor.
, even though the jimpObject
was a valid jimp object.
Downgrading to jimp 0.3.11
solved the problems for me.
Hey,
I am using this package in react app, and would like to pass in jimp object that was already preprocessed to replace color util as alternative to url to image (keep both options ofc). Jimp can not write to output when used on client side (or at least I could not make it work), so writing and reading again is not solution for me just to use this tool's interface.
I can fork this and adapt to my needs, just wanted to check if there are some restrictions to this, and if this would be useful to you, I can create PR for it?
type: rgb
Alpha is not supported so transparent color can't be defined.
type: hex
Based on this stackoverflow answer, transparent hex code is #AARRGGBB
, but it's an invalid parameter.
{ ReplaceColorError: Parameter is not valid
at Promise (node_modules\replace-color\src\replace-color.js:32:23)
at new Promise (<anonymous>)
at module.exports (node_modules\replace-color\src\replace-color.js:20:10)
(truncated)
name: 'ReplaceColorError',
code: 'PARAMETER_INVALID',
field: 'options.colors.targetColor' }
Is there a way to use transparent as one of the parameter? Thank you
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.