diff --git a/glymur/jp2k.py b/glymur/jp2k.py index ea3c859..2994742 100644 --- a/glymur/jp2k.py +++ b/glymur/jp2k.py @@ -238,7 +238,7 @@ class Jp2k(Jp2kBox): outfile += b'0' * num_pad_bytes cparams.outfile = outfile - if self.filename[-4:].lower() == '.jp2': + if self.filename[-4:].endswith(('.jp2', '.JP2')): cparams.codec_fmt = opj2.CODEC_JP2 else: cparams.codec_fmt = opj2.CODEC_J2K diff --git a/glymur/test/test_jp2k.py b/glymur/test/test_jp2k.py index 8b04dfa..c018897 100644 --- a/glymur/test/test_jp2k.py +++ b/glymur/test/test_jp2k.py @@ -224,6 +224,17 @@ class TestJp2k(unittest.TestCase): filename = 'this file does not actually exist on the file system.' Jp2k(filename) + @unittest.skipIf(os.name == "nt", "NamedTemporaryFile issue on windows") + def test_write_with_JP2_suffix(self): + """should be able to write with JP2 suffix.""" + j2k = Jp2k(self.j2kfile) + expdata = j2k.read() + with tempfile.NamedTemporaryFile(suffix='.JP2') as tfile: + ofile = Jp2k(tfile.name, 'wb') + ofile.write(expdata) + actdata = ofile.read() + np.testing.assert_array_equal(actdata, expdata) + @unittest.skipIf(os.name == "nt", "NamedTemporaryFile issue on windows") def test_write_srgb_without_mct(self): """should be able to write RGB without specifying mct"""