@@ -0,0 +1,2288 @@
+package org.xcolab.utils;%0A%0Aimport javax.imageio.ImageIO;%0Aimport java.awt.Color;%0Aimport java.awt.Graphics2D;%0Aimport java.awt.image.BufferedImage;%0Aimport java.io.ByteArrayOutputStream;%0Aimport java.io.IOException;%0A%0A/**%0A * Created by steve on 09/03/16.%0A */%0Apublic class FileUploadUtil %7B%0A%0A    public static byte%5B%5D resizeAndCropImage(BufferedImage img, int IMAGE_CROP_WIDTH_PIXELS, int IMAGE_CROP_HEIGHT_PIXELS) throws IOException %7B%0A        boolean containsTransparancy = containsAlphaPixels(img);%0A        BufferedImage resImg = resizeImage(img, IMAGE_CROP_WIDTH_PIXELS, IMAGE_CROP_HEIGHT_PIXELS, containsTransparancy);%0A%0A        ByteArrayOutputStream bos = new ByteArrayOutputStream();%0A        if (containsTransparancy) %7B%0A            ImageIO.write(resImg, %22png%22, bos);%0A        %7D else %7B%0A            ImageIO.write(resImg, %22jpg%22, bos);%0A        %7D%0A%0A        return bos.toByteArray();%0A    %7D%0A%0A    private static boolean containsAlphaPixels(BufferedImage img) %7B%0A        for (int x = 0; x %3C img.getWidth(); x++) %7B%0A            for (int y = 0; y %3C img.getHeight(); y++) %7B%0A                Color c = new Color(img.getRGB(x, y), true);%0A                if (c.getAlpha() %3C 255) %7B%0A                    return true;%0A                %7D%0A            %7D%0A        %7D%0A        return false;%0A    %7D%0A%0A    private static BufferedImage resizeImage(BufferedImage originalImage, int IMG_WIDTH, int IMG_HEIGHT, boolean containsTransparancy) %7B%0A        int w = originalImage.getWidth();%0A        int h = originalImage.getHeight();%0A%0A        int cropSize;%0A        int cropX = 0;%0A        int cropY = 0;%0A%0A        if (h %3C w) %7B%0A            cropSize = h;%0A            cropX = (w - h) / 2;%0A        %7D else %7B%0A            cropSize = w;%0A            cropY = (h - w) / 2;%0A        %7D%0A%0A        BufferedImage croppedImage = originalImage.getSubimage(cropX, cropY, cropSize,%0A                cropSize);%0A%0A        int type = BufferedImage.TYPE_INT_RGB;%0A        if (containsTransparancy) %7B%0A            type = BufferedImage.TYPE_INT_ARGB;%0A        %7D%0A%0A        BufferedImage resizedImage = new BufferedImage(IMG_WIDTH, IMG_HEIGHT, type);%0A        Graphics2D g = resizedImage.createGraphics();%0A        g.drawImage(croppedImage, 0, 0, IMG_WIDTH, IMG_HEIGHT, 0, 0, cropSize, cropSize,%0A                null);%0A        g.dispose();%0A%0A        return resizedImage;%0A    %7D%0A%0A%7D%0A

Add file-dependend image upload