Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win


Attached watermarking sign to picture using scripting?

Posted on 2004-08-09
Medium Priority
Last Modified: 2010-04-01
Hi there,

I know that my points currently not enough but i'm really would like to know the solution to my problem.

Hope someone will generous enough to help me.......

I would like to display pictures in a browser and i will also put a watermarking into the picture also.
So now my problem is that how to put "watermarking" to the pictures. The pictures are residing in
a folder...so when i use <img src="...."> to display it, a script will automatically put a watermarking
to all the pictures.

The watermarking that i'm saying is, for example...some pictures got a word "SAMPLE" attached to
the picture itself......

Usually graphic designer will put the "SAMPLE" word to each pictures in layer.... But i would like to know
if scripting could do the same.........

Please advice me on this...

Thanks in advanced

Question by:kennethcky
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
LVL 35

Accepted Solution

TimYates earned 100 total points
ID: 11750707
Not with javascript...

You could point the IMG src tag at a servlet, and have that servlet load the image you asked for, add some text to it using Java2D, and then return the final image as a JPG...


Author Comment

ID: 11750921

Do you have any Java2D that very close related to my problem that I could take a look?


Author Comment

ID: 11758970
Hi there,

I found a code which could solved my problem, but its using applet.....Could this code converted to
servlet and retrieve the pict from browser(jsp)?

Could someone advice me on this..?



import java.awt.*;
import java.awt.event.*;
import com.sun.image.codec.jpeg.*;
import java.awt.image.BufferedImage;
import java.awt.image.DataBuffer;
import java.awt.geom.*;
import java.io.*;
import javax.swing.*;

public class JPEGJ2d extends JApplet {

    private static Image img;

    public void init() {
        img = getToolkit().getImage(JPEGJ2d.class.getResource("duke.jpg"));
        try {
            MediaTracker tracker = new MediaTracker(this);
            tracker.addImage(img, 0);
        } catch (Exception e) {}

    public void paint(Graphics g) {
        Graphics2D g2 = (Graphics2D) g;
      Dimension d = getSize();
        g2.clearRect(0, 0, d.width, d.height);
      int w = d.width;
      int h = d.height;

        BufferedImage bi = (BufferedImage) createImage(w, h);
        Graphics2D big = bi.createGraphics();

        big.drawImage(img, 0, 0, null);
        big.setFont(new Font("Dialog", Font.PLAIN, 10));
        big.drawString("BufferedImage", 4, 12);

      //To rotate the image, comment the following line
        //g2.drawImage(bi, 0, 0, this);

      //comment including g2.drawimage() if you dont want to rotate
      double x = 0.5*w;
        double y = 0.5*h;
        AffineTransform at = new AffineTransform();
        g2.drawImage(bi, 0, 0, null);

        try {
             File file = new File("images", "test.jpg");
             FileOutputStream out = new FileOutputStream(file);

            JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);
            JPEGEncodeParam param = encoder.getDefaultJPEGEncodeParam(bi);
            param.setQuality(1.0f, false);

//          ImageIO.write(bi, "jpeg", out);
        } catch (Exception ex) {
            g2.drawString("write permissions on images/test.jpg?", 5, h*2-5);


    public static void main(String argv[]) {
        final JPEGJ2d demo = new JPEGJ2d();
        JFrame f = new JFrame("Java 2D(TM) Demo - JPEGJ2d");
        f.addWindowListener(new WindowAdapter() {
            public void windowClosing(WindowEvent e) {System.exit(0);}
        f.getContentPane().add("Center", demo);
        f.setSize(new Dimension(400,300));

Featured Post

Tech or Treat! - Giveaway

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

With so many activities to perform, Exchange administrators are always busy in organizations. If everything, including Exchange Servers, Outlook clients, and Office 365 accounts work without any issues, they can sit and relax. But unfortunately, it…
Let's take a look into the basics of ransomware—how it spreads, how it can hurt us, and why a disaster recovery plan is important.
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…

596 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question