Image manipulation in Node JS - node.js

I am new to node js and I want to convert a png image to pure black and white (not grayscale) image using native node js libraries. All I know that bit depth of black and white image should be 1. Any help is appreciated.

You have 2 options, both with the same package
https://www.npmjs.com/package/gm
Docs : http://aheckmann.github.io/gm/docs.html
Option 1
Convert the image in to monochrome
gm("img.png").monochrome()
Option 2
Use black and white thresholds to manually specify the ranges to be converted to pure black and white
//pixels below `threshold` become black.
gm("img.png").blackThreshold(red ,green , blue , opacity)
//pixels above the threshold become white
gm("img.png").whiteThreshold(red, green, blue, opacity)
Docs
http://aheckmann.github.io/gm/docs.html#blackThreshold
http://aheckmann.github.io/gm/docs.html#whiteThreshold
Personally I think Option 2 suits your needs best.

Related

Issue with color profile of CMYK image

The issue
I'm chasing a color issue that occurs during a gm convert of a jpg in CMYK colorspace to png. Just when I thought I'd isolated the issue and wanted to upload the images I realized that my issue has none to do with GraphicsMagick as the upload preview already showed the issue on the source image.
The source image
The majority of image tools (including XnView, browser) renders it light green.
Some image tools (including Faststone Image Viewer) render this image with dark green color:
To persist the issue
Running gm convert isolated-in.jpg png:isolated-out.png persists this light green for all image renderes.
The desired outcome
The dark green color is the desired outcome. I understand that there must be a corruption of the color profile of the input image. Infact, there seems to be none. However, some image tools render it correctly, making me beliefe there is a differet "guess" on the profile. What are those image tools doing so that it appears dark green? And, can I, with gm identify and/or gm convert correct for the missing/corrupted color profile of the source and persist the correct color, which is dark green?

GraphicsMagick adds black surroundings to transparent image

I'm using GraphicsMagick for node.js and I'm trying to edit the attached image but unfortunately it adds a black contour and I don't know why. Maybe it it because I transform it from png to jpeg? Any help is much appreciated!
gm(image.file.path)
.quality(70)
.strip()
.samplingFactor(4, 2)
.interlace('JPEG')
.colorspace('sRGB');
I don't speak node but try something like this to set the background colour to yellow and then flatten the image with transparency over the top.
gm(image.file.path)
.quality(70)
.strip()
.background('yellow'),
.flatten()
.samplingFactor(4, 2)
.interlace('JPEG')
.colorspace('sRGB');

color blending with GDI+

I am refering to a older question saying color blending with GDI+
Using GDI+ with Windows Forms, I want to be able to draw with a pen and blend color based on the destination pixel color.
For example, if I draw a line and it passes over black pixels, I want it to be a lighter color (like white for example) so that it's visible. When that same line passes over white pixels, it should be a darker color (black for example) so that it's still clearly visible.
the answers says to use a color matrix for transformation
so i started implementing it..
My image is present in raw data format in rgb48
Gdiplus::Bitmap image(input.width,input.height,input.width*6,PixelFormat48bppRGB,(unsigned char*)rgb48);
Gdiplus::Image *images= image.GetThumbnailImage(input.width,input.height);
Gdiplus::TextureBrush brush(images);
Gdiplus::Pen pen(&brush);
Gdiplus::ColorMatrix matrix={
-1.0f,0.0f,0.0f,0.0f,0.0f,
0.0f,-1.0f,0.0f,0.0f,0.0f,
0.0f,0.0f,-1.0f,0.0f,0.0f,
0.0f,0.0f,0.0f,1.0f,0.0f,
1.0f,1.0f,1.0f,0.0f,1.0f,
};
Gdiplus::Graphics gfx(&image1);
Gdiplus::ImageAttributes imageAttr;
imageAttr.SetColorMatrix(&matrix);
gfx.DrawImage(images,Gdiplus::Rect(0,0,input.width,input.height),0,0,1024,1024,Gdiplus::UnitPixel,&imageAttr);
I am not getting what i expect..Can some one help me in finding the mistake i m doing.
You can use the alpha component of a color to specify transparency, so that colors can be combined. However, if you want the combination to be something other than the alpha blend, you must draw the pixels yourself. You could first draw into a transparent bitmap, then render that onto the destination pixel by pixel.

Remove the picture edges

I downloaded a icon, and now i want to reset the color of it, but i'm not good at photoshop, i've set the color of it to be red, but there are to many edges and corners, please tell me how to remove those edges by using photoshop step by step, thanks a lot.
here is the icon i downloaded:
and this is my ugly one:
The best way to alter a single color like this on a simple image such as this is to alter the Hue and Saturation [CTRL / CMD + U]...
This allows you greater color control and keeps the anti-aliased edges of the image intact.
Most beginners alter colors like this by simply selecting the color with the wand, or using the paint bucket on the color. Unfortunately this usually does one of 2 things:
Makes the ragged edges that you saw.
Leaves a halo of the old color as an orphan.
I did this in a few seconds with that tool:

Transparent PNG with white edges

For some reason this PNG with a transparent background shows up with white edges but only when on a grey background of nearly the same shade, it's fine on black or light grey.
It's 24bit file and done the same way I done many times before in photoshop with no problems.
It is because it is antialiased against a white background. Try saving your PNG in proper 32 bit?
The antialiasing of the letters did not use any alpha value, they just rendered against your default background color. Anyway, it doesn't look fine on black, I saw the hard antialiased pixels immediately ;)

Resources