PNG Image Generation
/*
##########################
#
# Skrypcik zwraca plik .png zawierajacy obrazek z napisem
# wedlug zadanego tokenu
#
########### Maciej Stopa
#
# This is free software; you may redistribute it and/or modify
# it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 2,
# or (at your option) any later version.
#
# This is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
*/
package nip;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import javax.imageio.*;
import java.awt.image.*;
import java.awt.Graphics;
import java.awt.Color;
import java.awt.Font;
import java.awt.FontFormatException;
public class IMG extends HttpServlet {
public void doGet (HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {
doPost(request, response);
}
public void doPost (HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("image/png");
int width = 60;
int height = 14;
BufferedImage buffer = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
Graphics g = buffer.createGraphics();
Color kolor = new Color(Integer.parseInt("44ff88",16));
g.setColor(kolor);
g.fillRect(0,0,width,height);
int arc = 0;
g.setColor(Color.BLACK);
if (request.getParameter("token")!=null)
{
int value = Integer.valueOf(request.getParameter("token"));
String text = String.valueOf(99999999-(value*3));
if (text!=null)
{
g.drawString(text,0,height-2);
}
}
OutputStream os = response.getOutputStream();
ImageIO.write(buffer, "png", os);
os.close();
}
}