import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import java.io.File;
import javax.imageio.ImageIO;
public class ImageEmbedder {
public static void main(String[] args) {
// Load the base image template and the images to embed
BufferedImage baseImage = loadImage("base_image.png");
BufferedImage image1 = loadImage("image1.png");
BufferedImage image2 = loadImage("image2.png");
// Create a Graphics2D object to draw on the base image
Graphics2D g2d = baseImage.createGraphics();
// Embed the first image onto the base image at position (x1, y1)
int x1 = 100;
int y1 = 100;
g2d.drawImage(image1, x1, y1, null);
// Embed the second image onto the base image at position (x2, y2)
int x2 = 300;
int y2 = 200;
g2d.drawImage(image2, x2, y2, null);
// Save the modified base image as a new file
saveImage(baseImage, "output_image.png");
}
// Helper method to load an image from a file
public static BufferedImage loadImage(String filePath) {
BufferedImage image = null;
try {
image = ImageIO.read(new File(filePath));
} catch (Exception e) {
e.printStackTrace();
}
return image;
}
// Helper method to save an image to a file
public static void saveImage(BufferedImage image, String filePath) {
try {
ImageIO.write(image, "png", new File(filePath));
} catch (Exception e) {
e.printStackTrace();
}
}
}