Code from the book All The Image IO You Need To Know