Fix for Image.putdata segfault

Fixes #1008.