Need to bulk convert EPS --> BMP & other steps; what's wrong with this script?

Hello all - I’ve used GIMP several years for a variety of basic image needs at work, and have always been able to navigate through reasonably well before now.

I have 400 EPS files that I need to apply the following processing steps to. Because they’re pretty large (3.6GP apiece), I need to set up my machine overnight to run a batch instead of handling them by hand. The steps I need to apply are:

(1) Import the EPS file at 7200dpi.
(2) Crop to Content.
(3) Resize to 16384px width by scaled height using LoHalo interpolation.
(4) Flatten image layers to remove Alpha (transparent → white).
(5) Convert to indexed palette (optimal 255 colors), using no dithering.
(6) Export as BMP with run-length-encoding enabled and write color space info disabled.
(7) Repeat the above for all 400 EPS files in the same directory.

I’m using 3.02r1 on a Windows 11 machine, and I tried to write the script (meaning I fed the requirements into ChatGPT); it gave me the following Python-Fu, which I then dumped into batch-process-eps.scm in my Scripts folder, per Preferences–>Folders–>Scripts. But after a restart, the script didn’t appear in GIMP, including in a search, so there’s something missing.

I’m relatively familiar with R, VBA, SQL and some other programming languages, so scripting isn’t alien to me, and I could figure this out eventually (probably). But any help is appreciated. Maybe it needs to be Script-Fu instead of Python-Fu, or something needs modified, or I’m not registering it correctly. Or all three. Regardless, help is appreciated! Thank you.

#!/usr/bin/env python

from gimpfu import *
import os

def batch_process_eps(input_dir):
    # Get all EPS files in directory
    eps_files = [f for f in os.listdir(input_dir) if f.lower().endswith('.eps')]
    
    for eps_file in eps_files:
        input_path = os.path.join(input_dir, eps_file)
        output_path = os.path.splitext(input_path)[0] + '.bmp'
        
        # Load EPS with high resolution
        image = pdb.file_eps_load(input_path, input_path, 7200.0)
        
        # Crop to content
        pdb.plug_in_autocrop(image, image.active_layer)
        
        # Get current width for scaling ratio calculation
        current_width = image.width
        target_width = 16384
        scale_ratio = float(target_width) / float(current_width)
        new_height = int(image.height * scale_ratio)
        
        # Scale image using LoHalo
        pdb.gimp_image_scale_full(image, target_width, new_height, INTERPOLATION_LOHALO)
        
        # Flatten image
        image.flatten()
        
        # Convert to indexed
        pdb.gimp_image_convert_indexed(
            image,           # The image
            NO_DITHER,      # No dithering
            MAKE_PALETTE,   # Use optimal palette
            255,           # Number of colors
            False,         # No alpha
            False,         # No remove unused
            ""            # No palette name
        )
        
        # Export as BMP with RLE and no color space info
        pdb.file_bmp_save(
            image,
            image.active_layer,
            output_path,
            output_path,
            True,           # Run-length encoded
            False           # Do not write color space information
        )
        
        # Close the image
        pdb.gimp_image_delete(image)

    # Quit GIMP
    pdb.gimp_quit(0)

# Register the script
register(
    "batch_process_eps",
    "Batch process EPS files",
    "Process EPS files with specific parameters",
    "Your Name",
    "Your Name",
    "2025",
    "Batch Process EPS",
    "",
    [
        (PF_DIRNAME, "input_dir", "Input directory", "")
    ],
    [],
    batch_process_eps,
    menu="<Image>/File/Batch Process EPS"
)

main()

Have you tried actually writing the script? You can see a tutorial here: 4. A Python plug-in writing Tutorial

While we’re always happy to help, we’re not here to correct ChatGPT’s completely wrong output, and you have to at least try and solve your own problem.

Normally I would. However, I unfortunately lack the time to attempt it myself. This was assigned to me this afternoon, to be completed by tomorrow morning, and I already had another project to complete tonight. I understand if there’s no desire to help when ChatGPT was my only attempt but it was worth a shot. Thanks all the same and feel free to close the topic.

OK, I had time to make an actual (non-AI) attempt at the script. GIMP still doesn’t recognize it so something’s still wrong. I haven’t had a chance to check all the parameters yet, so maybe something’s wrong there? (I don’t know how to tell file-ps-load-setargs not to specify a width or height in pixels, for example; I tried both 0 and -1 so far.)

(script-fu-register
    "script-fu-resize-maps"
    "EPS to Indexed BMP"
    "Batch process to resize large EPS files to indexed BMPs"
    "NA"
    ""
    "May 5, 2025"
    "*"
    SF-STRING    "Images"    "~/Images/*.eps"
    SF-VALUE    "Resolution (dpi)"    "7200"
    SF-VALUE    "Width (pixels)"    "16384"
    )

(script-fu-menu-register "script-fu-resize-maps" "<Image>/Image/Transform")

(define (script-fu-resize-maps ask-fileglob ask-dpires ask-wpx)

    (let*
        ((thefiles (cadr (file-glob ask-fileglob 0))))
        (while (not (null? thefiles))
          (let*
            ((thefilename (car thefiles)) 
             (file-ps-load-setargs ask-dpires -1 -1 "1" 7 2 2)
             (image (car (file-ps-load RUN-NONINTERACTIVE thefilename thefilename)))
             (drawable (car (gimp-image-get-active-layer image)))
            )
            (gimp-image-undo-disable image)
            (plug-in-autocrop image image.active_layer)
            (ask-hpx = int(image.height * image.width / ask-wpx))
            (gimp-image-scale-full image ask-wpx ask-hpx INTERPOLATION_LOHALO)
            (image.flatten())
            (gimp-image-convert-indexed image NO_DITHER MAKE_PALETTE 255 False False "")
            (gimp-image-undo-enable image)
            (gimp-file-bmp-save RUN-NONINTERACTIVE image drawable thefilename thefilename True False)
            (gimp-image-delete image)
          )
          (set! thefiles (cdr thefiles))
        )
    )
)
1 Like

(post deleted by author)

Curses deleted by mistake. More haste less speed.

Is this for Gimp 2.10 or Gimp 3.0 - There are differences

As a very-much non-coder, Gimp 3.0 python has become very complicated, script-fu might be easier but maybe parsing a folder of files might be a problem.
Did you run Gimp in a terminal and see any error messages ?

The first step is get something, anything working, so for a single open file, that scales up and exports to bmp a Gimp 3.0 script-fu is attached.

As far as I know batch in Gimp 3.0 is still a command line procedure applying a script.

quick-save.scm (1.3 KB)

1 Like

While I don’t know the details, there have been some major changes in the plugin API with GIMP 3.0, so AI is very unlikely to be of any help. It also means you have to be careful with tutorials and such, since they may not have been updated yet. Your best bet is probably to install an older version.

Ah, thanks both. I didn’t consider the possibility that the tutorials I referenced might be out of date per the upgrade to GIMP 3. I’ll give 2.x a try and also see if I can part of it working by deleting part of the script.

You might consider using ImageMagick. The IM command could be something like this (Windows BAT syntax):

  magick ^
    -density 7200 ^
    %1 ^
    -trim +repage ^
    -resize 16384 ^
    -background White -layers Flatten ^
    +dither -colors 256 ^
    -compress RLE ^
    outdir\%%t.bmp

Beware that, depending on the input EPS file, the first stage of rasterizing at 7200dpi may create a large raster image eg 1 giga pixels which can eat memory.

When this does what you want for a single input file, put it in a for loop to process all the files in a directory.

Of course, if your assignment requires you to use Gimp, ignore my post.

Thank you. Yes, the resulting files are going to be 3.6 GP apiece so they’ll take a while to process.

I’ve made some progress. Turns out SF-VALUE no longer is valid in GIMP 3 and I have to use SF-ADJUSTMENT instead. More coming…

OK…it took a TON of work and a lot of research on what GIMP 3 allows. A lot of script-fu functions were deprecated or changed between GIMP 2 and 3. But I finally came up with a script that (mostly) works. I could still use help with three things though:

  • User is prompted for the directory to use, and all EPS files from that directory are added to “thefiles”
  • DPI actually gets passed to file-eps-load or file-ps-load (they don’t allow a resolution to be specified, and file-ps-load-setargs doesn’t appear to be supported anymore)
  • Change exported file name so it is .bmp instead of .eps

Thanks in advance.

(script-fu-register
    "script-fu-resize-maps"
    "Resize Map Files"
    "Batch process to resize maps for nuggets"
    "xyz"
    ""
    "May 6, 2025"
    "*"
    SF-STRING    "File Path"    "basepath"
    SF-ADJUSTMENT    "Resolution (dpi)"    '(3600 1 524288 1 100 0 1)
    SF-ADJUSTMENT    "Width (pixels)"    '(8192 1 524288 1 100 0 1)
    )
(script-fu-menu-register "script-fu-resize-maps" "<Image>/Image/Transform")

(define (script-fu-resize-maps ask-filedir ask-dpires ask-wpx)

    (let*
        ((thefiles (car (file-glob ask-filedir 0))))
        (while (not (null? thefiles))
          (let*
              ((thefilename (car thefiles))
              (image (car (file-eps-load 2 thefilename)))
              )
              (gimp-image-undo-disable image)
              (gimp-image-autocrop image)
              (let*
                  ((imageh (car (gimp-image-get-height image)))
                  (imagew (car (gimp-image-get-width image)))
                  (hpx (round (/ (* imageh ask-wpx) imagew))))
                  (gimp-context-set-interpolation INTERPOLATION-LOHALO)
                  (gimp-image-scale image ask-wpx hpx)
                  (gimp-image-flatten image)
                  (gimp-image-convert-indexed image CONVERT-DITHER-NONE CONVERT-PALETTE-GENERATE 255 0 1 "")
                  (gimp-image-undo-enable image)
                  (file-bmp-export RUN-NONINTERACTIVE image thefilename 0 1 0)
                  (gimp-image-delete image)
              )
          )
          (set! thefiles (cdr thefiles))
        )
    )
)
1 Like