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 :wink:

Hi Karthik,

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

hi @Srinivasch


import this dll from imports

Regards,
Aditya

hello should be “hello”
Arial, 10 - should be of font type
please check the workflow that i have uploaded

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
Aditya

Please update the datatypes of the variables defined.
You had set incorrect datatypes.

Please correct me if any.

@Srinivasch

aditya here,

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
Please close topic by marking useful reply as answer :slight_smile:

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,
aditya