JPEG to JPEG2000

12-28-2011 06:35 AM
New Contributor II
I am using PIL to convert .jpg's to .jp2's (for cache) for our mobile devices. I have not seen anything that says PIL supports JPEG2000... however, my script seems to work... the file sizes are smaller, and they show up more clear on the mobile devices (using ArcPad).

The issue is that only some of the cache scales are viewed without error on the mobile device, and I am wondering if I can use the code the way I am, or if I am essentially running into issues since PIL does not "support"  JPEG2000.

Anyone have any experience with this? Is there a better way to convert to .jp2, preferably with Python? Too bad you can't create your cache directly to .jp2.

import Image, os, sys
rootPath = myPath
for (path, dirs, files) in os.walk(rootPath):
    for file in files:
        if file.lower().endswith(".jpg"):
            jpgName = file.replace(".jpg","")
            jpg = + "\\" + file)
   + "\\" + jpgName + ".jp2", "JPEG")
Tags (2)
2 Replies
Esri Esteemed Contributor
Hi Ryan,

It doesn't appear that PIL support JPEG2000 as you mentioned.  You'll notice that if you right-click on the .jp2 in ArcCatalog > Properties the Compression type is still JPEG rather than JPG2000.  It appears this module better compresses imagery than ArcGIS, explaining while the new file is smaller in size.  I would keep the extension .jpg (rather than .jp2) and see if you still receive the error.
0 Kudos
New Contributor II
Thanks for the tip... and yes, they still are smaller just keeping them as .jpg (they are the ame size as the .jp2's would be). So, I'll have the mobile folks test this out and see how it goes.
0 Kudos