you do realize image formats are extremely complicated and specialized field of expertise, just take a look at the specs. and image compression algortihms like lzw for gifs, jpeg and png are again a very specialized field of expertise.
progress is a business application language and not very suited for these type of operations. for one there are no built in support for anything more then simple arithmetic etc. but why reinvent the wheel ?
shop around for api's or command line tools, maybe try a search for optimize for web that does something similar. i'd also check if the scanner api (probably twain) already has that functionality built in.
good luck, please tell us what solution you came up with.