from PIL import Image

#I think the code you gave could be improve by just
#rotating color values. We don't need a temp value
#My code is below

def swap_color():
    p = Image.open("danang.jpg")
    copy = p.copy()
    (w, h) = copy.size
    for width in range(w):
        for height in range(h):
            pix = copy.getpixel((width, height))
            (r, g, b) = pix
            np = (g,b,r)
            copy.putpixel((width, height), np)
    copy.show()

swap_color()
