The original message was received at 2010-01-13 07:16:01 -0800
from postoffice.(null) [10.0.0.1]

   ----- The following addresses had permanent fatal errors -----
<[email protected]>

   -----Transcript of session follows -----
... while talking to postoffice.(null).:
>>> RCPT To:<[email protected]>
<<< 550 5.1.1 unknown or illegal alias: [email protected]
550 <[email protected]>... User unknown
-- 
You received this message because you are subscribed to the Google Groups 
"Google Web Toolkit" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/google-web-toolkit?hl=en.


Reporting-MTA: dns; postoffice.(null)
Received-From-MTA: DNS; postoffice.(null)
Arrival-Date: 2010-01-13 07:16:01 -0800

Final-Recipient: RFC822; [email protected]
Action: failed
Status: 5.1.1
Remote-MTA: DNS; postoffice.(null)
Diagnostic-Code: SMTP;550 5.1.1 unknown or illegal alias: [email protected]
Last-Attempt-Date: 2010-01-13 07:16:01 -0800
--- Begin Message ---
=============================================================================
Today's Topic Summary
=============================================================================

Group: [email protected]
Url: http://groups.google.com/group/google-web-toolkit/topics

  - Image Generation [1 Update]
    http://groups.google.com/group/google-web-toolkit/t/6e2e50c917cda57a


=============================================================================
Topic: Image Generation
Url: http://groups.google.com/group/google-web-toolkit/t/6e2e50c917cda57a
=============================================================================

---------- 1 of 1 ----------
From: bryanb <[email protected]>
Date: Nov 21 11:58PM -0800
Url: http://groups.google.com/group/google-web-toolkit/msg/b4ca77b978533941

Something like this works for me.

On the server:

import java.awt.Container;
import java.awt.Graphics2D;
import java.awt.MediaTracker;
import java.awt.RenderingHints;
import java.awt.Toolkit;
import java.awt.image.BufferedImage;

import javax.imageio.ImageIO;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class ImageServlet extends HttpServlet {
        /**
         *
         */
        private static final long serialVersionUID = 1L;

        public void doGet(HttpServletRequest request, HttpServletResponse
response) {
                double thumbWidth;
                double thumbHeight;

                String imagefile = request.getParameter("file");
                String height = request.getParameter("h");
                String width = request.getParameter("w");

//              System.err.println(imagefile + ", " + height + ", " + width);

                // Set the mime type of the image
                response.setContentType("image/png");

                try {

                        java.awt.Image image = 
Toolkit.getDefaultToolkit().getImage
(imagefile);
                        MediaTracker mediaTracker = new MediaTracker(new 
Container());
                        mediaTracker.addImage(image, 0);
                        mediaTracker.waitForID(0);

                        int imageWidth = image.getWidth(null);
                        int imageHeight = image.getHeight(null);
                        double imageRatio = (double) imageWidth / (double) 
imageHeight;

                        // if width parameter is null, then just use it to scale
                        thumbHeight = new Double(height);

                        if (width != null) {
                                thumbWidth = new Double(width);
                                // determine size from WIDTH and HEIGHT
                                double thumbRatio = thumbWidth / thumbHeight;

                                if (thumbRatio < imageRatio) {
                                        thumbHeight = thumbWidth / imageRatio;
                                } else {
                                        thumbWidth = thumbHeight * imageRatio;
                                }
                        } else {
                                thumbWidth = thumbHeight * imageRatio;
                        }

                        // draw original image to thumbnail image object and 
scale it to
the new size on-the-fly
                        BufferedImage thumbImage = new BufferedImage((int) 
thumbWidth,
(int) thumbHeight, BufferedImage.TYPE_INT_RGB);
                        Graphics2D graphics2D = thumbImage.createGraphics();
                        
graphics2D.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
RenderingHints.VALUE_INTERPOLATION_BILINEAR);
                        graphics2D.drawImage(image, 0, 0, (int) thumbWidth, 
(int)
thumbHeight, null);
                        graphics2D.dispose();

                        ImageIO.write(thumbImage, "png", 
response.getOutputStream());
                } catch (Exception e) {
                        e.printStackTrace();

                }
        }
}


On the client, create a URL to get the image something like this:

StringBuffer sb = new StringBuffer(GWT.getHostPageBaseURL());
sb.append("ImageServlet?file=");
sb.append(imagefilel);
sb.append("&h=" + Utils.getPageHeight());
sb.append("&w=" + Utils.getPageWidth());
Image image = new Image(sb.toString);




--

You received this message because you are subscribed to the Google Groups 
"Google Web Toolkit" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/google-web-toolkit?hl=.



--- End Message ---

Reply via email to