It would be great if we could add tests for this function with some real image files. I'm not even sure how to test this PR and when we convert to Imagine it would be nice to catch regressions.