package com.mobi5.commons.domain.logic;
import java.io.File;
import java.io.FileOutputStream;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.*;
import java.awt.image.BufferedImage;
import com.sun.image.codec.jpeg.JPEGCodec;
import com.sun.image.codec.jpeg.JPEGImageEncoder;
public class Imgproce {
private int wideth;
private int height;
private String t=null;
public void setT(String t)
{
this.t=t;
}
public void setWideth(int wideth)
{
this.wideth=wideth;
}
public int getWideth()
{
return this.wideth;
}
public void setHeight(int height)
{
this.height=height;
}
public int getHeight(int w,int h) //former images size
{
int hhh;
if(w > wideth)
{
float ww;
ww = (float) w / (float) wideth;
float hh = h / ww;
return (int) hh;
}
else
{
this.setWideth(w);
return h;
}
}
public void proce(String fpath) throws Exception
{
File _file = new File(fpath);
System.out.println("-------"+fpath);
Image src = javax.imageio.ImageIO.read(_file);
int wideth=src.getWidth(null);
int height=src.getHeight(null);
int h=this.getHeight(wideth,height);
BufferedImage tag = new BufferedImage(this.getWideth(),h,BufferedImage.TYPE_INT_RGB);
Graphics g=tag.getGraphics();
g.drawImage(src, 65, 60, this.getWideth(), h, null);
if(t!=null)
{
g.setColor(new Color(242,242,242));
g.fillRect(this.getWideth() - 120, h - 18,120,18);
g.setColor(new Color(180,180,180));
g.drawRect(this.getWideth() - 120, h - 18,119,17);
g.setColor(new Color(255,102,0));
g.drawString(t, this.getWideth() - 100, h - 5);
}
FileOutputStream out=new FileOutputStream(fpath);
JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);
encoder.encode(tag);
out.close();
}
}