goja-core/src/main/java/goja/core/libs/Images.java
public void add(File dest, File file, int position) {
        if (dest.exists() && !dest.isDirectory()) {
            String fn = file.getName().toLowerCase();
            int opacityType = fn.endsWith(".png") || fn.endsWith("gif") ?
                    BufferedImage.TYPE_INT_ARGB : BufferedImage.TYPE_INT_RGB;
            Image destImg;
            try {
                destImg = ImageIO.read(dest);
            } catch (IllegalArgumentException e) {
                throw new RuntimeException(e);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
            int width = destImg.getWidth(null);
            int height = destImg.getHeight(null);

            final BufferedImage image = new BufferedImage(width, height, opacityType);

            Image src;
            try {
                src = ImageIO.read(file);
            } catch (IllegalArgumentException e) {
                throw new RuntimeException(e);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
            int ww = src.getWidth(null);
            int hh = src.getHeight(null);
            int WW, HH;
            switch (position) {
                case 1:
                    WW = 0;
                    HH = 0;
                    break;
                case 2:
                    WW = (width - ww) / 2;
                    HH = 0;
                    break;
                case 3:
                    WW = width - ww;
                    HH = 0;
                    break;
                case 4:
                    WW = 0;
                    HH = (height - hh) / 2;
                    break;
                case 5:
                    WW = (width - ww) / 2;
                    HH = (height - hh) / 2;
                    break;
                case 6:
                    WW = width - ww;
                    HH = (height - hh) / 2;
                    break;
                case 7:
                    WW = 0;
                    HH = height - hh;
                    break;
                case 8:
                    WW = (width - ww) / 2;
                    HH = height - hh;
                    break;
                default:
                    WW = width - ww;
                    HH = height - hh;
            }
            Graphics g = image.createGraphics();
            g.drawImage(src, WW, HH, ww, hh, null);
            g.dispose();
        }
    }
public void add(File dest, File file, int position) {
        if (dest.exists() && !dest.isDirectory()) {
            String fn = file.getName().toLowerCase();
            int opacityType = fn.endsWith(".png") || fn.endsWith("gif") ?
                    BufferedImage.TYPE_INT_ARGB : BufferedImage.TYPE_INT_RGB;
            Image destImg;
            try {
                destImg = ImageIO.read(dest);
            } catch (IllegalArgumentException e) {
                throw new RuntimeException(e);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
            int width = destImg.getWidth(null);
            int height = destImg.getHeight(null);

            final BufferedImage image = new BufferedImage(width, height, opacityType);

            Image src;
            try {
                src = ImageIO.read(file);
            } catch (IllegalArgumentException e) {
                throw new RuntimeException(e);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
            int ww = src.getWidth(null);
            int hh = src.getHeight(null);
            int WW, HH;
            switch (position) {
                case 1:
                    WW = 0;
                    HH = 0;
                    break;
                case 2:
                    WW = (width - ww) / 2;
                    HH = 0;
                    break;
                case 3:
                    WW = width - ww;
                    HH = 0;
                    break;
                case 4:
                    WW = 0;
                    HH = (height - hh) / 2;
                    break;
                case 5:
                    WW = (width - ww) / 2;
                    HH = (height - hh) / 2;
                    break;
                case 6:
                    WW = width - ww;
                    HH = (height - hh) / 2;
                    break;
                case 7:
                    WW = 0;
                    HH = height - hh;
                    break;
                case 8:
                    WW = (width - ww) / 2;
                    HH = height - hh;
                    break;
                default:
                    WW = width - ww;
                    HH = height - hh;
            }
            Graphics g = image.createGraphics();
            g.drawImage(src, WW, HH, ww, hh, null);
            g.dispose();
        }
    }
将指定的图片加入到当前图片中的指定位置. 即向图片中打水印.

@param file     要添加的图片文件。
@param position 要添加的图片在当前图片中的位置. <br /> 其取值范围为1-9之间的整数(默认为9)。分别代表：左上、上中、右上、左中、正中、右中、左下、中下、右下