Solved

Attached watermarking sign to picture using scripting?

Posted on 2004-08-09
3
214 Views
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

0
Comment
Question by:kennethcky
  • 2
3 Comments
 
LVL 35

Accepted Solution

by:
TimYates earned 25 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...

Tim
0
 

Author Comment

by:kennethcky
ID: 11750921
hi,

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


thanks
0
 

Author Comment

by:kennethcky
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..?

thanks

---------------------------------------------------------------------------------

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() {
        setBackground(Color.white);
        img = getToolkit().getImage(JPEGJ2d.class.getResource("duke.jpg"));
        try {
            MediaTracker tracker = new MediaTracker(this);
            tracker.addImage(img, 0);
            tracker.waitForID(0);
        } catch (Exception e) {}
    }


    public void paint(Graphics g) {
        Graphics2D g2 = (Graphics2D) g;
      Dimension d = getSize();
        g2.setBackground(getBackground());
        g2.clearRect(0, 0, d.width, d.height);
        g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
                            RenderingHints.VALUE_ANTIALIAS_ON);
        g2.setRenderingHint(RenderingHints.KEY_RENDERING,
                            RenderingHints.VALUE_RENDER_QUALITY);
      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.setColor(Color.black);
        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();
        at.rotate(Math.toRadians(90),x,y);
        g2.transform(at);
        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);
            encoder.setJPEGEncodeParam(param);
            encoder.encode(bi);

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

          g2.dispose();
       
    }


    public static void main(String argv[]) {
        final JPEGJ2d demo = new JPEGJ2d();
        demo.init();
        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.pack();
        f.setSize(new Dimension(400,300));
        f.show();
    }
}
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

FAQ pages provide a simple way for you to supply and for customers to find answers to the most common questions about your company. Here are six reasons why your company website should have a FAQ page
An article on effective troubleshooting
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

813 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now