Crap Nullpointer Exceptions

This is the blog of John Dulaney, a hacker of Fedora, SCAdian, player of Music, blacksmith, sailor, and consumer of Bacon.

Tag Archives: Image Conversion

Batch convert .jp2 files to png from the command line with GIMP

I have a bunch of Sanborn maps in JPEG 2000 (.jp2) format that are quite large.  The problem is that the the proprietary CAD software I use does not support this particular file format.  Therefore, I need to convert to something it does support; I chose png.  To convert all the files in a directory at once, I cd into that directory and run this:

jdulaney@gefjon:~/$ gimp -n -i -b – <<EOF
(let* ( (file’s (cadr (file-glob “*.jp2” 1))) (filename “”) (image 0) (layer 0) )
(while (pair? file’s)
(set! image (car (gimp-file-load RUN-NONINTERACTIVE (car file’s) (car file’s))))
(set! layer (car (gimp-image-merge-visible-layers image CLIP-TO-IMAGE)))
(set! filename (string-append (substring (car file’s) 0 (- (string-length (car file’s)) 4)) “.png”))
(gimp-file-save RUN-NONINTERACTIVE image layer filename filename)
(gimp-image-delete image)
(set! file’s (cdr file’s))
(gimp-quit 0)