Byte aray to gif image?

I got a little assignment to write a function that takes a bytearray (byte []) as one of its parameters . This array actuallycontains a gif image . Then the requirement is to convert it into jpgor png as requested by the user and return another byte array thatcontains the result .