Jump to content

help with recieving an image


crowfoot

Recommended Posts

Hi all.

 

I have a java applet that returns an edited image back to php (sposed to) however my java developer cannot tell me how to do this in php. There is a parameter we pass to the applet postURL which is the location of the php script to "process the image" ie. save in specified location or resize etc however i'm having trouble doing this. ie' i have no idea where to start. I have pasted the code he is using inside the java applet once the save button is hit if it helps.

 

I guess he is using the post method. any help or a couple of lines to just display this image would be great.

 

    public void saveImage() throws IOException {
        if (postURL == null) {
            postURL = new     public void saveImage() throws IOException {
        if (postURL == null) {
            postURL = new
URL("");
        }
        PostMethod method = new PostMethod(postURL.toExternalForm());
        ByteArrayOutputStream stream = new ByteArrayOutputStream();
        int width, height;
        BufferedImage thisImage = images.get(currentImage);
        BufferedImage postImage;
        if (isWheel) {
            width = height = 120;
        } else {
            width = 600;
            height = (int)
                   (600.0 / thisImage.getWidth() * thisImage.getHeight());
        }

        postImage = new BufferedImage(width, height, BufferedImage.TYPE_4BYTE_ABGR);
        Graphics2D graphics = postImage.createGraphics();
        graphics.drawImage(thisImage, 0, 0, width, height, null);
        graphics.dispose();

        ImageIO.write(postImage, "PNG", stream);
        byte[] bytes = stream.toByteArray();
        Part[] parts = {
            new StringPart("UserId", userId),
            new StringPart("Category", isWheel ? "Wheel" : "SideOnShot"),
            new FilePart("Image", new ByteArrayPartSource("image.png",
bytes))
        };
        method.setRequestEntity(
                new MultipartRequestEntity(parts, method.getParams()));
        HttpClient client = new HttpClient();
        int status = client.executeMethod(method);
        if (status < 200 || status > 299) {
            throw new HttpStatusException(status);
        }
    }
URL(" ");
        }
        PostMethod method = new PostMethod(postURL.toExternalForm());
        ByteArrayOutputStream stream = new ByteArrayOutputStream();
        int width, height;
        BufferedImage thisImage = images.get(currentImage);
        BufferedImage postImage;
        if (isWheel) {
            width = height = 120;
        } else {
            width = 600;
            height = (int)
                   (600.0 / thisImage.getWidth() * thisImage.getHeight());
        }

        postImage = new BufferedImage(width, height, BufferedImage.TYPE_4BYTE_ABGR);
        Graphics2D graphics = postImage.createGraphics();
        graphics.drawImage(thisImage, 0, 0, width, height, null);
        graphics.dispose();

        ImageIO.write(postImage, "PNG", stream);
        byte[] bytes = stream.toByteArray();
        Part[] parts = {
            new StringPart("UserId", userId),
            new StringPart("Category", isWheel ? "Wheel" : "SideOnShot"),
            new FilePart("Image", new ByteArrayPartSource("image.png",
bytes))
        };
        method.setRequestEntity(
                new MultipartRequestEntity(parts, method.getParams()));
        HttpClient client = new HttpClient();
        int status = client.executeMethod(method);
        if (status < 200 || status > 299) {
            throw new HttpStatusException(status);
        }
    }

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.