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
https://forums.phpfreaks.com/topic/117808-help-with-recieving-an-image/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.