wrote most functions in createimage