Page 1 of 1

java to php

Posted: Wed Feb 24, 2010 10:32 am
by ashwin_nath_m
Please help me convert this function to php

Code: Select all

 
public static byte[] imageToBytes(Image img) {
        //scaled image to bytes
        int width = img.getWidth();
        int height = img.getHeight();
        try {
            int[] argb = new int[width * height];
            ByteArrayOutputStream bout = new ByteArrayOutputStream();
            DataOutputStream dout = new DataOutputStream(bout);
            try {
                img.getRGB(argb, 0, width, 0, 0, width, height);
 
 
                dout.writeInt(width);
                dout.writeInt(height);
                for (int i = 0; i < argb.length; i++) {
                    dout.writeInt(argb[i]);
                }
                return bout.toByteArray();
            } catch (OutOfMemoryError ex) {
                System.gc();
                return "".getBytes();
            }
        } catch (Exception e) {
            // this won't happen, because we're writing to a ByteArrayOutputStream
            return "".getBytes();
        }
    }
 
Thanks in advance ;-)

Re: java to php

Posted: Wed Feb 24, 2010 11:55 am
by pickle
"Help" means you've tried it yourself and are struggling with a particular part.

Re: java to php

Posted: Wed Feb 24, 2010 1:21 pm
by ashwin_nath_m
i'm strugglibg with whole part donno wer 2 begin :(

Posted: Wed Feb 24, 2010 4:35 pm
by Jonah Bron
You should start by learning the basics of PHP. Here's a good place to start:

http://w3schools.com/php/

Re: java to php

Posted: Wed Feb 24, 2010 4:36 pm
by alex.barylski
Heres how to start :)

Code: Select all

 
 
class Image{
  // TODO: Implement image class
}
 
public static imageToBytes(Image $img)
{
 // Implement method
}
 
Cheers,
Alex