1
$\begingroup$

A bit of context first, I setup a Node group that helps me scale textures to real world scale. So I use the images DPI or PPM for this. Thus I scripted the inputs for the Node groups to automatically grab the relevant information.

It works fine with PNG and TIF but not with JPEG. I use the script below to gather the DPI.

node_tree.nodes["IMAGE12"].image.resolution.y

For JPEGs, I get the wrong DPI, 72 dpi (2834.646 ppm). Even it the correct value should be higher, blender always displays 72dpi.

So, is there a script to access the EXIF of images directly? so that I get the correct DPI all the time.

Thanks

$\endgroup$

1 Answer 1

1
$\begingroup$

OK, found a solution.

Basically, blender is missing an EXIF reader. Luckily, python has the modules. We just need to install it.

Below is a basic method to install a module https://b3d.interplanety.org/en/how-to-install-required-packages-to-the-blender-python-with-pip/

But did not work for me. Perhaps, its because of the office firewall or network....

So I installed the module using the wheel file, .whl, with the function below with blender (Not a powershell)

import subprocess
import sys
import os

# path to python.exe
python_exe = os.path.join(sys.prefix, 'bin', 'python.exe')

# install required packages
subprocess.call([python_exe, "-m", "pip", "install", "C:/LOCATION AND FILENAME.whl"])

Don't need to install pip because since 2.8 its already installed.

I am using the ExifRead module. Arbitrary selection. The code below gets me the dpi I want.

import exifread

# Open image file for reading (binary mode)
f = open('C:/Users/csemeon/Desktop/Fabric/RED 1200dpi.jpg', 'rb')

# Return Exif tags
tags = exifread.process_file(f)

for tag in tags.keys():
    if tag in ('Image XResolution'):
        #print ('Key: %s, value %s' % (tag, tags[tag]))
        dpitest =  str(tags['Image XResolution'])
        dpi = float(dpitest)

Had to use a two steps to convert the value to float (or int). Because the Dpi is a tag and doesn't convert directly to float.

Hope it helps someone.

$\endgroup$
2
  • $\begingroup$ I'd recommend to file a bug report if the dpi values are wrong... Just go to Help > Report a Bug to let the blender devs know about that. In best case this workaround is redundant at some point. $\endgroup$
    – brockmann
    Commented Jan 12, 2021 at 10:36
  • $\begingroup$ Also read: Using 3rd party Python modules $\endgroup$
    – brockmann
    Commented Jan 12, 2021 at 10:46

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .