Default image DPI is inconsistent between GUI and Script-Fu
GIMP version: 2.10.14 (latest version for macOS as of writing)
Operating System: macOS, Linux
Package: gimp.org installer, Ubuntu package
Description of the bug
We use GIMP in a headless batch mode to convert and resize a bunch of images. One operation we do is to resize images from one DPI to another while maintaining the same print size -- essentially calculating a new pixel width & height based on the difference from the current DPI to the desired DPI. We do this via a collection of Scheme scripts we run.
We noticed that for images where the DPI is not specified in metadata, GIMP was assuming that the DPI was 300.0 (as returned by
gimp-image-get-resolution) instead of the more traditional 72.0 DPI that most applications assume. This results in our calculations being off and producing the wrong image size. However, if I open the image in the GIMP GUI and then run the scripts from the Script-Fu console, the DPI is assumed to be 72.0 as expected. I can't see any reason why opening via GUI vs script should intentionally differ here.
I'm not too familiar with the GIMP source code, but I did look around for where these values could come from and how they are calculated, and it does look like the GUI follows a different code path than the
gimp-file-load function does in Scheme. While the normal function appears to be
file_load_invoker. A crucial difference between these two is that the former calls
file_import_image here which sets the DPI to 72.0 here, but
file_load_invoker does not, and seems to be the source of the discrepancy.
Is the bug reproducible? Always
- Open an image file with no explicit DPI metadata using
gimp-image-get-resolutionin a script, and observe that it returns
(300.0 300.0)instead of
Expected result: The default DPI should always be 72.0 for imported images.
Actual result: The default DPI is 72.0 when importing via the GUI, but 300.0 when imported via a script.
gimp --version --verbose:
GIMP is started as MacOS application GNU Image Manipulation Program version 2.10.14 git-describe: Unknown, shouldn't happen C compiler: Configured with: --prefix=/Applications/Xcode-10.app/Contents/Developer/usr --with-gxx-include-dir=/Library/Developer/CommandLineTools/SDKs/MacOSX10.9.sdk/usr/include/c++/4.2.1 Apple LLVM version 10.0.0 (clang-1000.11.45.2) Target: x86_64-apple-darwin17.7.0 Thread model: posix InstalledDir: /Applications/Xcode-10.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin using babl version 0.1.72 (compiled against version 0.1.72) using GEGL version 0.4.18 (compiled against version 0.4.18) using GLib version 2.62.4 (compiled against version 2.62.4) using GdkPixbuf version 2.40.0 (compiled against version 2.40.0) using GTK+ version 2.24.32 (compiled against version 2.24.32) using Pango version 1.44.7 (compiled against version 1.44.7) using Fontconfig version 2.13.1 (compiled against version 2.13.1) using Cairo version 1.16.0 (compiled against version 1.16.0)
We also run the scripts inside Ubuntu containers, but the bug is reproducible on both macOS and Ubuntu that I have observed.