nathan-osman / gimp-webp

Gimp plugin for loading and saving WebP images
GNU General Public License v3.0
70 stars 8 forks source link

run-mode parameter is ignored #1

Closed 0ion9 closed 9 years ago

0ion9 commented 9 years ago

Hi, I was just trying to add webp support to my 'export selection' plugin, and found this bug.

In brief, when you attempt to call the PDB procedure file-webp-save from another plugin, it pops up the export settings dialog regardless of the fact it is being called non-interactively (run-mode = GIMP_RUN_NONINTERACTIVE). This is incorrect and interrupts whatever UI the calling plugin was presenting.

To quote the plugin writing guide:

Run-modes

One can run a plug-in in several different ways, it can be run from a GIMP menu if The GIMP is run interactively, or from a script or a batch, or from the "Filters->Repeat Last" shortcut.

The "run_mode" input parameter can hold one of these values: "GIMP_RUN_INTERACTIVE", "GIMP_RUN_NONINTERACTIVE" or "GIMP_RUN_WITH_LAST_VALS".

"GIMP_RUN_INTERACTIVE" is typically the only case where one creates an options dialog. Otherwise, one directly calls the processing with values from input parameters or from memory.

A simple test case is:

  1. load an image into GIMP.
  2. open the Python-Fu console
  3. Enter the following commands into it, one by one:
i = gimp.image_list()[0]
pdb.file_webp_save(i, i.layers[0], '/tmp/output.webp','/tmp/output.webp', 90)
pdb.file_webp_save(i, i.layers[0], '/tmp/output.webp','/tmp/output.webp', 90, run_mode=RUN_NONINTERACTIVE)
pdb.file_webp_save(i, i.layers[0], '/tmp/output.webp','/tmp/output.webp', 90, run_mode=RUN_INTERACTIVE)

(Note that the first and second call to pdb.file_webp_save are equivalent, as run_mode=RUN_NONINTERACTIVE is the default when calling from Python-Fu. Also note that all of the calls to file_webp_save pop up the settings dialog, whereas only the final call (with RUN_INTERACTIVE) should actually do this. ) You can compare this with, for example, the behaviour of pdb.file_png_save(i, i.layers[0], '/tmp/output.png','/tmp/output.png', 1,9,1,1,1,1,1) and pdb.file_png_save(i, i.layers[0], '/tmp/output.png','/tmp/output.png', 1,9,1,1,1,1,1, run_mode=RUN_INTERACTIVE)

nathan-osman commented 9 years ago

Thanks for pointing this out. I'll take a look at this tomorrow since it's getting quite late here.

nathan-osman commented 9 years ago

This has now been fixed. I'll eventually be adding some more save parameters to allow more customization, such as enabling lossless mode and adjusting the quality of the alpha channel.

0ion9 commented 9 years ago

Thanks, that was a very prompt response.