Merge an image over another at a specified position and save it as a new image?
save an image that is created by merging an image with another image?
I have an image first and I want to insert some text above that image at the position specified .... what I got coorectly..bt a new task is to place this last generated image on top of another image template in a location and save it as a new jpg image in my working directory.
+2
a source to share
1 answer
Here is an example on how to use Image Overlay with java2D. Since you noted with jquery as well, I'm not sure if you want to do this with jquery or java.
I meant the second snippet, corrected and executed
import java.awt.AlphaComposite;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.net.URL;
import javax.imageio.ImageIO;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
public class WaterMark {
public static void main(String[] args) throws IOException {
URL url = new URL("http://sstatic.net/so/img/logo.png");
BufferedImage im = ImageIO.read(url);
URL url2 = new URL("http://sstatic.net/sf/img/logo.png");
BufferedImage im2 = ImageIO.read(url2);
Graphics2D g = im.createGraphics();
g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.4f));
g.drawImage(im2, (im.getWidth()-im2.getWidth())/2, (im.getHeight()-im2.getHeight())/2, null);
g.dispose();
display(im);
ImageIO.write(im, "jpeg", new File("sample_output.jpeg"));
}
public static void display(BufferedImage image) {
JFrame f = new JFrame("WaterMark");
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.getContentPane().add(new JLabel(new ImageIcon(image)));
f.pack();
f.setLocationRelativeTo(null);
f.setVisible(true);
}
}
+4
a source to share