Have you tried also using binmode when reading the file?
In reply to Re: image encode base64 - help needed by Corion in thread image encode base64 - help needed by zurich