And here replace with `if paletted and Image:`, this way the code won't fail if the variable is set but PIL is not installed.