# Could any one let me know how to add a text in image file using UIPath

Could any one let me know how to add a text in image file using UIPath. I have a scenario where I have to modify text in an existing image (.JPG) file and replace it with my own text. Eg: Send birthday emails to employees on daily basis.

This is a sample c# code for writing text on image.
For writing we use Graphics library.

string firstText = "Hello";
string secondText = "World";

PointF firstLocation = new PointF(10f, 10f);
PointF secondLocation = new PointF(10f, 50f);

string imageFilePath = @"path\picture.bmp"
Bitmap bitmap = (Bitmap)Image.FromFile(imageFilePath);//load the image file

using(Graphics graphics = Graphics.FromImage(bitmap))
{
using (Font arialFont =  new Font("Arial", 10))
{
graphics.DrawString(firstText, arialFont, Brushes.Blue, firstLocation);
graphics.DrawString(secondText, arialFont, Brushes.Red, secondLocation);
}
}

bitmap.Save(imageFilePath);//save the image file


More details on Graphics.DrawString -

Regards,
Karthik Byggari

2 Likes

Thanks Karthik.
Is it possible using UIPath.

Yes. You have to create variables of correct data types and with Assign Activities you can achieve that.
I don’t have sample workflow now. I will send you the sample workflow today or tomorrow at the latest.

Regards,
Karthik Byggari

Thanks much Karthik. I will try but plz provide me the sample workflow at your convenient time.

1 Like

Main.xaml (7.0 KB)

try this

Hi Karthik,

When I tried I am getting the below error. Kindly check and correct if anything missing.

import this dll from imports

Regards,

hello should be “hello”
Arial, 10 - should be of font type

Hi Karthik,

I even tried that.

Sry for bothering you.

Click on variables pane there i have defined a variable call font
Just change that as per your need

Regards

Please update the datatypes of the variables defined.

@Srinivasch

Thanks Aditya…now no errors but while running i am getting the below error.

Hi
please set input file path and new file path different
input file C:\path\to\image\file.jpg
new file path C:\path\to\image\file12324.jpg

Thanks Much…its working

@Srinivasch

Is there any possibility to get the data from excel file instead of hardcoding in FirstText.

@Srinivasch

make that firstText and newfilepath variables as arguments

and pass necessary excel data.

regards,