Add Watermark to PNG in Java - Watermark Generator

The boom in the online industry and E-Commerce has brought many formalities to streamline business processes. It has become a challenge to keep your brand images protected with your brand names or logos. Therefore, GroupDocs.Watermark offers Cloud SDKs and REST APIs to programmatically add text to PNG files. However, you can automate the process to add watermark to PNG images that eventually give a competitive edge to your online business software. Therefore, let’s walk through some methods and write a code snippet to build a watermark generator that will be used to add watermark to images using GroupDocs.Watermark Cloud SDKs for Java.

The following sections will be covered in this article:

Watermark Generator API Installation

Let’s install and set up this watermark to images library by performing very simple steps. If you have set up Java on your machine then install this library by downloading the JAR file or using the following Maven configurations:

<repository>
    <id>groupdocs-artifact-repository</id>
    <name>GroupDocs Artifact Repository</name>
    <url>https://repository.groupdocs.cloud/repo</url>
</repository>
<dependency>
    <groupId>com.groupdocs</groupId
    <artifactId>groupdocs-watermark-cloud</artifactId>
    <version>22.3</version>
    <scope>compile</scope>
</dependency>

The next step is to avail API credentials (Client ID, Client Secret) from the API Cloud dashboard to make API calls to the GroupDocs.Watermark Cloud SDKs for Java. For this purpose, please visit this guide if you face any difficulty in obtaining your Client ID & Client Secret.

Add Watermark to PNG in Java

Now, we can leverage the enterprise-level method and properties exposed by watermark generator library. These methods and classes are self-explanatory and easy to use.

Note: We have the source PNG file in API Cloud dashboard that you can upload manually or programmatically by calling the UploadFile method.

The following steps are to add text to PNG images:

  • Create an object of the Configuration class and initialize it with Client ID and Client Secret.
  • Initialize an instance of the WatermarkApi class with the instance of the configuration.
  • Create an object of the FileInfo class.
  • Now, set PNG file path by calling the setFilePath method.
  • Define Watermark options by creating an instance of the WatermarkOptions class.
  • Invoke the setFileInfo method to define the source file.
  • Define text watermark options such as watermark text, font family, font size, etc.
  • Set Watermark text color by creating an object of the Color class and invoking the setForegroundColor method.
  • Define watermark details by calling the setTextWatermarkOptions method of the WatermarkDetails class.
  • Create an object of the Position class and set watermark position.
  • Create a request to add watermark by creating an instance of the AddRequest class.
  • Invoke the add method of the WatermarkApi class to add watermark to PNG.

The following code sample demonstrates how to add watermark to PNG in Java:

Run the server, and you will find your watermarked file in the API Cloud dashboard. However, you can download file manually or programmatically by invoking the DownloadFile method. 

You can see the output in the image below:

create your own watermark online free

Create Your Own Watermark Online Free

GroupDocs.Watermark also offers an online tool to add watermark to images. So, this online free watermark maker lets you add text to your brand images and you can open it in mobile or web browsers. Above all, this online tool is quick, user-friendly and there is no subscription needed to use this tool.

free watermark maker

Conclusion

We are ending this blog post here with the hope that you have learned how to add watermark to PNG in Java. In addition, we walked through the steps and code snippet to implement the whole functionality. Further, you may visit the documentation of this watermark generator library to add text to PNG programmatically. Moreover, you can visit our live APIs for a real-time experience. So, please follow our Getting Started guide to start development.

Help is Available

You can let us know about your questions or queries on our forum.

Frequently Asked Questions – FAQs

How do I add a watermark to a PNG file?

Please use this free online watermark generator to add watermark to the images.

How to add text to an image in Java?

You can opt for GroupDocs.Watermark Cloud SDKs for Java to add watermark to PNG images programmatically. Moreover, please visit this link to see the code snippet and steps.

See Also