The second version is likely correct, but you need to change each int(rgbr), int(rgbg), int(rgbb) with:
int(rgbr)
int(rgbg)
int(rgbb)
rgbr = int(rgbr) rgbg = int(rgbg) rgbb = int(rgbb)
Without any further information about the error, I cannot help further.