[Image-SIG] Corruption writing PNG data

Ben Taylor benj at pml.ac.uk
Fri Jul 26 14:02:16 CEST 2013


Hi all

I've got some data that should be fine (came from a known-good netCDF
file) but causes PIL to write an invalid image if it is used to save in
PNG format (it's happy writing GIF format).

The same code writes PNGs quite happily 99% of the time, but just
occasionally we generate a netCDF that causes this bug - we don't know
why. We're not sure if the problem is actually in PIL or if it might be
in libpng. Anyone mind taking a look please?

Test data at ftp://rsg.pml.ac.uk/rsg/benj/pil_problem/:
data.npz - Numpy npz data with data that causes the issue
working_data.npz - npz file from another source that works fine
test_harness.py - Run this with the two test files to demonstrate the
problem - the PNG generated from data.npz is corrupt.

Test harness code below (just to demonstrate it's nothing complicated).

TIA
Ben

#!/usr/bin/env python

import numpy
import Image

def test(infile, prefix):

   npz = numpy.load(infile)
   imagedata = npz['arr_0']
   palette = npz['arr_1']

   out_image = Image.fromarray(imagedata, 'P')
   out_image.putpalette(palette)

   out_image.save(prefix + ".gif") # ok
   out_image.save(prefix + ".png") # bust
# end function

test("data.npz", "broken")
test("working_data.npz", "working")

-- 
Ben Taylor <benj at pml.ac.uk>, http://rsg.pml.ac.uk/
Remote Sensing Group, Plymouth Marine Laboratory
Tel: +44 (0)1752 633432, Fax: +44 (0)1752 633101


Latest news: www.pml.ac.uk and @PlymouthMarine

Plymouth Marine Laboratory (PML) is a company limited by guarantee registered in England & Wales, company number 4178503. Registered Charity No. 1091222. Registered Office: Prospect Place, The Hoe, Plymouth  PL1 3DH, UK. 

This message is private and confidential. If you have received this message in error, please notify the sender and remove it from your system. You are reminded that e-mail communications are not secure and may contain viruses; PML accepts no liability for any loss or damage which may be caused by viruses.



More information about the Image-SIG mailing list