Use imagecolorsforindex for creating the colors in rgb values to avoid issues with gif images