crowfoot Posted August 2, 2008 Share Posted August 2, 2008 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); } } Quote Link to comment Share on other sites More sharing options...
zq29 Posted August 3, 2008 Share Posted August 3, 2008 Have you read the manual? php.net/gd Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.