watermark in image using nodejs - node.js

I have added watermark on image using node_module 'gm', i had make font color grey but i found an bug in that if image content grey color so my watermark merged with image so i can't read the watermark text, that's why i want to create an overlay between image and watermark text but i don't know how i achieve it my current code is
const image = gm(__dirname+'/download.jpeg').fill('#ffffff').font('Arial', 10, '#ffffff').drawText(10, 20, "some text");
image.write('result.png', err => {
if(err) return console.error(err);
});
and i don't know how to make overlay between them my actual image is
and my watermarked image is
any help should be appreciate thanks in advance

So there is no such module that can give you the expected result.
But I faced the same problem & came across this module "node-caption" but again this module is also not giving us the expected result. So I have tweaked this module a little bit & made it work as expected.
Here is the URL to the modified module of my git hub repo https://github.com/mohsincynexis/node-caption.
The changes are only in the generate.js file.
Here is the attached image after watermark.

Related

Python and Kivy: How to update Image from memory?

I'm currently trying to display an image with kivy on a Raspbery Pi 4. The problem is that no image is shown on the Image widget. Also no Error or something else is given out to the terminal.
This is what I came up with in show_picture() in .py file:
image = camera.takePicture()
encode_param = [int(cv.IMWRITE_JPEG_QUALITY), 95]
result, enc_img = cv.imencode('.jpg', image, encode_param)
data = io.BytesIO(enc_img)
texture_ = CoreImage(data, ext="jpg").texture
The texture_ object was declared and initialized at class level with:
texture_ = StringProperty(None)
And in the .kv file I have following for the Image widget:
Image:
id: imageView
source: app.texture_
allow_stretch: True
I want the image to be updated via this method so that the gui shows the latest taken image. If someone has a different approach I'm also happy with it.
Thanks in advance.
Edit: messed something up when copying code

Is there a way to ignore EXIF orientation data when loading an image with PIL?

I'm getting some unwanted rotation when loading images using PIL. I'm loading image samples and their binary mask, so this is causing issues. I'm attempting to convert the code to use openCV instead, but this is proving sticky. I haven't seen any arguments in the documentation under Image.load(), but I'm hoping there's a workaround I just haven't found...
There is, but I haven't written it all up. Basically, if you load an image with EXIF "Orientation" field set, you can get that parameter.
First, a quick test using this image from the PIL GitHub source Pillow-7.1.2/Tests/images/hopper_orientation_6.jpg and run jhead on it you can see the EXIF orientation is 6:
jhead /Users/mark/StackOverflow/PillowBuild/Pillow-7.1.2/Tests/images/hopper_orientation_6.jpg
File name : /Users/mark/StackOverflow/PillowBuild/Pillow-7.1.2/Tests/images/hopper_orientation_6.jpg
File size : 4951 bytes
File date : 2020:04:24 14:00:09
Resolution : 128 x 128
Orientation : rotate 90 <--- see here
JPEG Quality : 75
Now do that in PIL:
from PIL import Image
# Load that image
im = Image.open('/Users/mark/StackOverflow/PillowBuild/Pillow-7.1.2/Tests/images/hopper_orientation_6.jpg')
# Get all EXIF data
e = im.getexif()
# Specifically get orientation
e.get(0x0112)
# prints 6
Now click on the source and you can work out how your image has been rotated and undo it.
Or, you could be completely unprofessional ;-) and create a function called SneakilyRemoveOrientationWhileNooneIsLooking(filename) and shell out (subprocess) to exiftool and remove the orientation with:
exiftool -Orientation= image.jpg
Author's "much simpler solution" detailed in above comment is misleading so I just wanna clear that up.
Pillow does not automatically apply EXIF orientation transformation when reading an image. However, it has a method to do so: PIL.ImageOps.exif_transpose(image)
OpenCV automatically applies EXIF orientation when reading an image. You can disable this behavior by using the IMREAD_IGNORE_ORIENTATION flag.
I believe the author's true intention was to apply the EXIF orientation rather than ignore it, which is exactly what his solution accomplished.

Write File in a specific size NODE JS

I receive an image in base64 string and I wanted to save the image in 3 different sizes. My code for saving the image in my app is as following and it works, how can I set a sepcific size for the image ?
fs.writeFile(pathImage, new Buffer(base64String, "base64"), function (err) {}
You can't just save an image in different sizes by writing part of the file to disk. In order to resize your image you need to first know what image format you are working with and then use an appropriate library to resize the image, usually by reducing image quality or cropping the image.
For example if you are working with a JPEG, PNG, WebP, or TIFF images, you could use https://github.com/lovell/sharp
From its example page
const sharp = require('sharp');
sharp(inputBuffer)
.resize(320, 240)
.toFile('output.webp', (err, info) => ... );

Graphicsmagick: How to draw text to fit a specific box (width/height)

I'm using GraphicsMagick's node.js module.
In my Node JS application I need to add a text label to an existing image, such that:
1) If the text is longer than the image size, the text auto-wraps around to the next line
2) If the text is not able to fit into the image, the font size of the text is automatically adjusted (reduced) to fit into the box of the image
The available APIs from GraphicsMagick's node.js module are:
gm("img.png").drawText(x, y, text [, gravity])
But this does not provide any options to fit the text into the box per the two requirements above. If I use this API alone I will need to manually break the text, and change the text font size to fit the image, but even for that I will need to first be able to measure the text size. Is there a way to do that?
Any suggestions?
For illustration purpose, below image shows three different text strings that need to fit into the same sized box. Hope it clarifies.
I have lost half a day, but can reach solve for this question. I use gm with gm.subClass({ imageMagick: true }). I think you can use it with a few changing for fully resolve your problem.
public createPreview(text: string) {
this.imageGenerator(800, 600, '#4c4cfc')
.fill('#FFFFFF')
.font('../../../client/assets/fonts/GraphikLCG-Bold.woff')
.fontSize('46')
.out('-background', '#4c4cfc')
.out('-size', '400x', 'caption:' + text)
.out('-gravity', 'center')
.out('-composite')
.write('./brandNewImg.jpg', (err: any) => {
console.log(err);
});
}

how to correct the orientation of the image with ITK-VTK

I am a beginner in VTK ITK, I am trying to read a DICOM series with ITK and display with VTK but I had pictures upside down, I tried to read a single image (JPG) with ITK and visualuser with VTK it is the same problem, so I had the idea of ​​treating the image on photoshop ie I applied to the original image rotation (vertical symmetry of the work area) and I did the reading with ITK and display with VTK, the image is displayed in the correct orientation, infact ITK keeps the orientation of the image, but the problem is at VTK, it is which displays the image upside down, I searched all over the internet I have not found a solution or a method or not even an idea, I encountered the same problem in many forums but there is no response, I count on your help, I can not apply any image processing to find a solution to this problem.
Please Help! thank you in advance
Ideally you should re-orient your camera in VTK so that it is suited for medical image visualization. (The default camera in VTK uses the computer graphics conventions).
If you want a quick hack, you can copy-paste the following code in ITK:
FlipFilterType::Pointer flipperImage = FlipFilterType::New();
bool flipAxes[3] = { false, true, false };
flipperImage = FlipFilterType::New();
flipperImage->SetFlipAxes(flipAxes);
flipperImage->SetInput( image );
flipperImage->Update();
I use a rapid way to set the orientation:
imageActor->SetOrientation(180,0,0);
No need to add filter.
Here's an example of how I would do it. I'm not sure what classes you are using, so I cannot be specific.
vtkSmartPointer<vtkImageData> result = vtkSmartPointer<vtkIMageData>::New();
result->DeepCopy(YourImage); //DeepCopy your image to result
rImage->Update();
double val;
int i = 0;
for(vtkIdType f = result->GetNumberOfPoints()-1; f > -1; f--)
{
val = YourImage->GetPointData()->GetScalars()->GetTuple1(f);
result->GetPointData()->GetScalars->SetTuple1(i,val);
i++;
}
result->Update();
//Now Visualize your image

Resources