We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Add diagonal watermark to existing .tif

I am trying to find a way to add a watermark to a .tif document using diagonal text. I am able to use aspose.imaging to add a watermark but cannot find a way to add the text with diagonal orientation. I see this is supported with word documents, however, in my case the document was created as a .tif in an imaging system.

Hi Mark,


Thank you for considering Aspose products.

I am afraid, currently there are no direct means available to update an existing image with a diagonal watermark while using Aspose.Imaging component. I will work with the development team to find a workaround for your scenario, and log an appropriate ticket (if required) for this feature. Please spare us little time to look into this problem.

We are sorry for your inconvenience.

An alternate solution for us could be to insert an image on top of the other image and save the result. Is this possible using the latest version of aspose.imaging ?

Hi Mark,


Thank you for your patience.

Although there are no direct means available in current version of Aspose.Imaging component to stamp the loaded images with diagonal watermarks. But still this can be achieved using the Graphic and Transformation Matrix. Please review the sample code as provided below, and the attached output image for your reference.

C# Souce Code

//Load an existing Tiff image
using (TiffImage multiImage = (TiffImage)Aspose.Imaging.Image.Load(myDir + “zeebra.tif”))
{
//Iterate over the TiffFrames in TiffImage
//Tiff Image could have several Frames
foreach (TiffFrame tiffFrame in multiImage.Frames)
{
//Declare a String object with Watermark Text
String theString = “45 Degree Rotated Text”;

//Create and initialize an instance of Graphics class
Graphics graphics = new Graphics(tiffFrame);

//Initialize an object of SizeF to store image Size
SizeF sz = graphics.Image.Size;

//Creates an instance of Font, initialize it with Font Face, Size and Style
Aspose.Imaging.Font font = new Aspose.Imaging.Font(“Times New Roman”, 14, FontStyle.Bold);

//Create an instance of SolidBrush and set its various properties
Aspose.Imaging.Brushes.SolidBrush brush = new Aspose.Imaging.Brushes.SolidBrush();
brush.Color = Color.White;
//Set Opacity of Brush object between 0 to 1
//0 means fully visible, 1 means invisible
brush.Opacity = 0;

//Initialize an object of StringFormat class and set its various properties
Aspose.Imaging.StringFormat format = new StringFormat();
format.Alignment = StringAlignment.Center;
format.FormatFlags = StringFormatFlags.MeasureTrailingSpaces;

//Create an object of Matrix class for transformation
Matrix matrix = new Matrix();
//First a translation
matrix.Translate(sz.Width/2 , sz.Height/2);
//Then a rotation
matrix.Rotate(-45.0f);

//Set the Transformation through Matrix
graphics.Transform = matrix;

//Draw the string on Image
graphics.DrawString(theString, font, brush, 0,0, format);
}
//Export to Tiff file format using the default options
multiImage.Save(myDir + “output.tiff”);
}