Hello
On my web application, I need to resize images sent via multipart forms.

When I try a console application using awt on my mac (see attached code), the console application starts a real Mac application with window and menu, while my code is only calling non-gui functions (ImageIO.read...) .

I'm really affraid to add this code on my server, and I wonder if this may have impact on memory, performance and stability of the server. I would rather prefer a little imaging library like jmagick or gd for java, small and efficient. It's not 100% java but it does not create windows and menus...

What do you use to resize images on the server size ?
Thanks a lot.

--
Riccardo Cohen
+33 (0)6 09 83 64 49
Société Realty-Property.com
1 rue de la Monnaie
37000 Tours
France

<http://www.appartement-maison.fr>
import java.awt.Font;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

import javax.imageio.ImageIO;

public class Main {
        public static void main(String[] args)
        {
                String mode = "draw";
                
                BufferedImage image1 = null;
                BufferedImage image2 = null;
                BufferedImage image3 = null;
                
                BufferedImage image1_converted = null;
                BufferedImage image2_converted = null;
                BufferedImage image3_converted = null;
                
                String path1 = "images/image1.jpg";
                String path2 = "images/image2.gif";
                String path3 = "images/image3.png";
                
                String ext1 = "jpg";
                String ext2 = "gif";
                String ext3 = "png";
                
                int outputWidth = 200;
                int outputHeight = 100;
                
                try{
                        image1 = ImageIO.read(new File(path1));
                }catch(IOException ex){System.out.println("Iexeption 
image1");ex.printStackTrace();}
                try{
                        image2 = ImageIO.read(new File(path2));
                }catch(IOException ex){System.out.println("Iexeption image2"); 
ex.printStackTrace();}
                try{
                        image3 = ImageIO.read(new File(path3));
                }catch(IOException ex){System.out.println("Iexeption image3"); 
ex.printStackTrace();}
                
                int width1 = image1.getWidth();
                int height1 = image1.getHeight();
                int width2 = image2.getWidth();
                int height2 = image2.getHeight();
                int width3 = image3.getWidth();
                int height3 = image3.getHeight();
                
                System.out.println(path1);
                System.out.println("width : " + width1);
                System.out.println("height : " + height1);
                
                System.out.println("\n" + path2);
                System.out.println("width : " + width2);
                System.out.println("height : " + height2);
                
                System.out.println("\n" + path3);
                System.out.println("width : " + width3);
                System.out.println("height : " + height3);
                
                if(mode.equals("resize"))
                {
                        image1_converted = new BufferedImage(outputWidth, 
outputHeight, image1.getType());
                        Graphics2D g1 = image1_converted.createGraphics();
                        g1.drawImage(image1, 0, 0, outputWidth, outputHeight, 
null);
                        g1.dispose();
                        
                        image2_converted = new BufferedImage(outputWidth, 
outputHeight, image2.getType());
                        Graphics2D g2 = image2_converted.createGraphics();
                        g2.drawImage(image2, 0, 0, outputWidth, outputHeight, 
null);
                        g2.dispose();
                        
                        image3_converted = new BufferedImage(outputWidth, 
outputHeight, image3.getType());
                        Graphics2D g3 = image3_converted.createGraphics();
                        g3.drawImage(image3, 0, 0, outputWidth, outputHeight, 
null);
                        g3.dispose();
                }
                else
                {
                        
                        image1_converted = new BufferedImage(width1, height1, 
image1.getType());
                        Graphics2D g1 = image1_converted.createGraphics();
                        //System.out.println(g1.getFont().toString());
                        g1.drawImage(image1, 0, 0, width1, height1, null);
                        g1.setFont(new Font("Dialog", 2, 200));
                        g1.drawString("test", width1/2, height1/2);
                        g1.dispose();
                        
                        image2_converted = new BufferedImage(width2, height2, 
image2.getType());
                        Graphics2D g2 = image2_converted.createGraphics();
                        g2.drawImage(image2, 0, 0, width2, height2, null);
                        g2.setFont(new Font("Dialog", 2, 200));
                        g2.drawString("test", width2/2, height2/2);
                        g2.dispose();
                        
                        image3_converted = new BufferedImage(width3, height3, 
image3.getType());
                        Graphics2D g3 = image3_converted.createGraphics();
                        g3.drawImage(image3, 0, 0, width3, height3, null);
                        g3.setFont(new Font("Dialog", 2, 200));
                        g3.drawString("test", width3/2, height3/2);
                        g3.dispose();
                }
                
                try{
                        ImageIO.write(image1_converted, ext1, new 
File("images/image1_converted."+ext1)); 
                }catch(IOException ex){System.out.println("Oexeption 
image1");ex.printStackTrace();}
                try{
                        ImageIO.write(image2_converted, ext2, new 
File("images/image2_converted."+ext2)); 
                }catch(IOException ex){System.out.println("Oexeption 
image2");ex.printStackTrace();}
                try{
                        ImageIO.write(image3_converted, ext3, new 
File("images/image3_converted."+ext3)); 
                }catch(IOException ex){System.out.println("Oexeption 
image3");ex.printStackTrace();}
        }
}
_______________________________________________
resin-interest mailing list
resin-interest@caucho.com
http://maillist.caucho.com/mailman/listinfo/resin-interest

Reply via email to