wrong image resolution (dpi) reported for certain jpg files from Photoshop #87857

Open
opened 2021-04-27 11:44:39 +02:00 by Vartan · 10 comments

System Information
Happens on any os.

Blender Version
Broken: (example: 2.91.2, edbf15d3c0, master, 2018-11-28, as found on the splash screen)
Also happens on any other version

Short description of error
Dear Blender team,
Sorry if I am reporting this issue in the wrong place.
I am closely working with blender API and recently discovered a weird behavior that when image resolution cant be parsed from image metadata the blender return some random value.

img = bpy.data.images.load("C:\Users\VartanSaakian\Desktop\testPng\test2.jpg")
print(img.resolution)

<Vector (2834.6458, 2834.6458)>

See the example - in fact, image DPI is 300.

image.png

Exact steps for others to reproduce the error
Just use following code and see the image resolution ->
img = bpy.data.images.load(image_path)

**System Information** Happens on any os. **Blender Version** Broken: (example: 2.91.2, edbf15d3c044, master, 2018-11-28, as found on the splash screen) Also happens on any other version **Short description of error** Dear Blender team, Sorry if I am reporting this issue in the wrong place. I am closely working with blender API and recently discovered a weird behavior that when image resolution cant be parsed from image metadata the blender return some random value. >>> img = bpy.data.images.load("C:\\Users\\VartanSaakian\\Desktop\\testPng\\test2.jpg") >>> print(img.resolution) <Vector (2834.6458, 2834.6458)> See the example - in fact, image DPI is 300. ![image.png](https://archive.blender.org/developer/F10041418/image.png) **Exact steps for others to reproduce the error** Just use following code and see the image resolution -> img = bpy.data.images.load(image_path)
Author

Added subscriber: @Rey4eel

Added subscriber: @Rey4eel
Member

Added subscriber: @lichtwerk

Added subscriber: @lichtwerk
Member

Changed status from 'Needs Triage' to: 'Needs User Info'

Changed status from 'Needs Triage' to: 'Needs User Info'
Member

This should have improved by 6f88053d85.
Have you tried with 2.92 or a fresh build from https://builder.blender.org/download/?

Could you share your example .jpg?
(please also read through #84661 (Can't read metadata data (EXIF) information in JPEG files), there seem to be files reporting their dpi in an unsupported format -- maybe yours is one of these as well?)

This should have improved by 6f88053d85. Have you tried with 2.92 or a fresh build from https://builder.blender.org/download/? Could you share your example .jpg? (please also read through #84661 (Can't read metadata data (EXIF) information in JPEG files), there seem to be files reporting their dpi in an unsupported format -- maybe yours is one of these as well?)
Author

Dear Philipp,

Thanks for your quick reply.
I am going to try now the latest beta version and give you feedback.

Regarding the image please find both in "jpeg" and "PSD" format.
Currently, I am parsing image Exif data from c++ and all required property are there, so it would be easier to get such info from Blender and it is also more officiant.

Please see the MetaData of this file bellow:
**
File Name : sample1.jpg
Directory : C:/Users/VartanSaakian/Desktop/testPng/_src
File Size : 15 MiB
File Modification Date/Time : 2021:04:20 15:56:07+02:00
File Access Date/Time : 2021:04:27 12:05:07+02:00
File Creation Date/Time : 2021:04:21 15:25:28+02:00
File Permissions : -rw-rw-rw-
File Type : JPEG
File Type Extension : jpg
MIME Type : image/jpeg
Exif Byte Order : Big-endian (Motorola, MM)
Orientation : Horizontal (normal)
X Resolution : 300
Y Resolution : 300
Resolution Unit : inches
Software : Adobe Photoshop 21.2 (Windows)
Modify Date : 2021:04:20 15:56:03
Color Space : sRGB
Exif Image Width : 8031
Exif Image Height : 5906
Compression : JPEG (old-style)
Thumbnail Offset : 318
Thumbnail Length : 10592
Current IPTC Digest : c75d17e574b56ef5dbbe3994c0e9795c
Coded Character Set : UTF8
Application Record Version : 0
IPTC Digest : c75d17e574b56ef5dbbe3994c0e9795c
Displayed Units X : inches
Displayed Units Y : inches
Print Style : Centered
Print Position : 0 0
Print Scale : 1
Global Angle : 120
Global Altitude : 30
URL List :
Slices Group Name : ATLHD3802
Num Slices : 1
Pixel Aspect Ratio : 1
Photoshop Thumbnail : (Binary data 10592 bytes, use -b option to extract)
Has Real Merged Data : Yes
Writer Name : Adobe Photoshop
Reader Name : Adobe Photoshop 2020
Photoshop Quality : 10
Photoshop Format : Standard
Progressive Scans : 3 Scans
XMP Toolkit : Adobe XMP Core 6.0-c002 116.164766, 2021/02/19-23:10:07
Creator Tool : Adobe Photoshop CS6 (Macintosh)
Create Date : 2020:06:19 10:18:46+01:00
Metadata Date : 2021:04:20 15:56:03+02:00
Format : image/jpeg
Instance ID : xmp.iid:ab1bce7d-054d-ce49-9665-b13b611bb475
Document ID : adobe:docid:photoshop:ea7ba80f-affa-f44f-99c1-3e63466ba6a0
Original Document ID : xmp.did:BA371CA52A21681183D1BF601154B4EE
Color Mode : RGB
ICC Profile Name : sRGB IEC61966-2.1
History Action : created, saved, saved, converted, derived, saved
History Instance ID : xmp.iid:BA371CA52A21681183D1BF601154B4EE, xmp.iid:BB371CA52A21681183D1BF601154B4EE, xmp.iid:481ccf6d-4b4b-4d44-8a81-1cb3e7110ec2, xmp.iid:ab1bce7d-054d-ce49-9665-b13b611bb475
History When : 2020:06:19 10:18:46+01:00, 2020:06:19 11:54:52+01:00, 2021:04:20 15:56:03+02:00, 2021:04:20 15:56:03+02:00
History Software Agent : Adobe Photoshop CS6 (Macintosh), Adobe Photoshop CS6 (Macintosh), Adobe Photoshop 21.2 (Windows), Adobe Photoshop 21.2 (Windows)
History Changed : /, /, /
History Parameters : from application/vnd.adobe.photoshop to image/jpeg, converted from application/vnd.adobe.photoshop to image/jpeg
Derived From Instance ID : xmp.iid:481ccf6d-4b4b-4d44-8a81-1cb3e7110ec2
Derived From Document ID : xmp.did:BA371CA52A21681183D1BF601154B4EE
Derived From Original Document ID: xmp.did:BA371CA52A21681183D1BF601154B4EE
Document Ancestors : 5A959E4C690430DB9154A750CD2C237E, xmp.did:DA3EDBE7E820681180839027ED94AB0A
Profile CMM Type : Linotronic
Profile Version : 2.1.0
Profile Class : Display Device Profile
Color Space Data : RGB
Profile Connection Space : XYZ
Profile Date Time : 1998:02:09 06:49:00
Profile File Signature : acsp
Primary Platform : Microsoft Corporation
CMM Flags : Not Embedded, Independent
Device Manufacturer : Hewlett-Packard
Device Model : sRGB
Device Attributes : Reflective, Glossy, Positive, Color
Rendering Intent : Media-Relative Colorimetric
Connection Space Illuminant : 0.9642 1 0.82491
Profile Creator : Hewlett-Packard
Profile ID : 0
Profile Copyright : Copyright (c) 1998 Hewlett-Packard Company
Profile Description : sRGB IEC61966-2.1
Media White Point : 0.95045 1 1.08905
Media Black Point : 0 0 0
Red Matrix Column : 0.43607 0.22249 0.01392
Green Matrix Column : 0.38515 0.71687 0.09708
Blue Matrix Column : 0.14307 0.06061 0.7141
Device Mfg Desc : IEC http://www.iec.ch
Device Model Desc : IEC 61966-2.1 Default RGB colour space - sRGB
Viewing Cond Desc : Reference Viewing Condition in IEC61966-2.1
Viewing Cond Illuminant : 19.6445 20.3718 16.8089
Viewing Cond Surround : 3.92889 4.07439 3.36179
Viewing Cond Illuminant Type : D50
Luminance : 76.03647 80 87.12462
Measurement Observer : CIE 1931
Measurement Backing : 0 0 0
Measurement Geometry : Unknown
Measurement Flare : 0.999%
Measurement Illuminant : D65
Technology : Cathode Ray Tube Display
Red Tone Reproduction Curve : (Binary data 2060 bytes, use -b option to extract)
Green Tone Reproduction Curve : (Binary data 2060 bytes, use -b option to extract)
Blue Tone Reproduction Curve : (Binary data 2060 bytes, use -b option to extract)
DCT Encode Version : 100
APP14 Flags 0 : [14]
APP14 Flags 1 : (none)
Color Transform : YCbCr
Image Width : 8031
Image Height : 5906
Encoding Process : Baseline DCT, Huffman coding
Bits Per Sample : 8
Color Components : 3
Y Cb Cr Sub Sampling : YCbCr4:4:4 (1 1)
Image Size : 8031x5906
Megapixels : 47.4
Thumbnail Image : (Binary data 10592 bytes, use -b option to extract)**

sample1.jpg

sample1.PSD

Dear Philipp, Thanks for your quick reply. I am going to try now the latest beta version and give you feedback. Regarding the image please find both in "jpeg" and "PSD" format. Currently, I am parsing image Exif data from c++ and all required property are there, so it would be easier to get such info from Blender and it is also more officiant. Please see the MetaData of this file bellow: ** File Name : sample1.jpg Directory : C:/Users/VartanSaakian/Desktop/testPng/_src File Size : 15 MiB File Modification Date/Time : 2021:04:20 15:56:07+02:00 File Access Date/Time : 2021:04:27 12:05:07+02:00 File Creation Date/Time : 2021:04:21 15:25:28+02:00 File Permissions : -rw-rw-rw- File Type : JPEG File Type Extension : jpg MIME Type : image/jpeg Exif Byte Order : Big-endian (Motorola, MM) Orientation : Horizontal (normal) X Resolution : 300 Y Resolution : 300 Resolution Unit : inches Software : Adobe Photoshop 21.2 (Windows) Modify Date : 2021:04:20 15:56:03 Color Space : sRGB Exif Image Width : 8031 Exif Image Height : 5906 Compression : JPEG (old-style) Thumbnail Offset : 318 Thumbnail Length : 10592 Current IPTC Digest : c75d17e574b56ef5dbbe3994c0e9795c Coded Character Set : UTF8 Application Record Version : 0 IPTC Digest : c75d17e574b56ef5dbbe3994c0e9795c Displayed Units X : inches Displayed Units Y : inches Print Style : Centered Print Position : 0 0 Print Scale : 1 Global Angle : 120 Global Altitude : 30 URL List : Slices Group Name : ATLHD3802 Num Slices : 1 Pixel Aspect Ratio : 1 Photoshop Thumbnail : (Binary data 10592 bytes, use -b option to extract) Has Real Merged Data : Yes Writer Name : Adobe Photoshop Reader Name : Adobe Photoshop 2020 Photoshop Quality : 10 Photoshop Format : Standard Progressive Scans : 3 Scans XMP Toolkit : Adobe XMP Core 6.0-c002 116.164766, 2021/02/19-23:10:07 Creator Tool : Adobe Photoshop CS6 (Macintosh) Create Date : 2020:06:19 10:18:46+01:00 Metadata Date : 2021:04:20 15:56:03+02:00 Format : image/jpeg Instance ID : xmp.iid:ab1bce7d-054d-ce49-9665-b13b611bb475 Document ID : adobe:docid:photoshop:ea7ba80f-affa-f44f-99c1-3e63466ba6a0 Original Document ID : xmp.did:BA371CA52A21681183D1BF601154B4EE Color Mode : RGB ICC Profile Name : sRGB IEC61966-2.1 History Action : created, saved, saved, converted, derived, saved History Instance ID : xmp.iid:BA371CA52A21681183D1BF601154B4EE, xmp.iid:BB371CA52A21681183D1BF601154B4EE, xmp.iid:481ccf6d-4b4b-4d44-8a81-1cb3e7110ec2, xmp.iid:ab1bce7d-054d-ce49-9665-b13b611bb475 History When : 2020:06:19 10:18:46+01:00, 2020:06:19 11:54:52+01:00, 2021:04:20 15:56:03+02:00, 2021:04:20 15:56:03+02:00 History Software Agent : Adobe Photoshop CS6 (Macintosh), Adobe Photoshop CS6 (Macintosh), Adobe Photoshop 21.2 (Windows), Adobe Photoshop 21.2 (Windows) History Changed : /, /, / History Parameters : from application/vnd.adobe.photoshop to image/jpeg, converted from application/vnd.adobe.photoshop to image/jpeg Derived From Instance ID : xmp.iid:481ccf6d-4b4b-4d44-8a81-1cb3e7110ec2 Derived From Document ID : xmp.did:BA371CA52A21681183D1BF601154B4EE Derived From Original Document ID: xmp.did:BA371CA52A21681183D1BF601154B4EE Document Ancestors : 5A959E4C690430DB9154A750CD2C237E, xmp.did:DA3EDBE7E820681180839027ED94AB0A Profile CMM Type : Linotronic Profile Version : 2.1.0 Profile Class : Display Device Profile Color Space Data : RGB Profile Connection Space : XYZ Profile Date Time : 1998:02:09 06:49:00 Profile File Signature : acsp Primary Platform : Microsoft Corporation CMM Flags : Not Embedded, Independent Device Manufacturer : Hewlett-Packard Device Model : sRGB Device Attributes : Reflective, Glossy, Positive, Color Rendering Intent : Media-Relative Colorimetric Connection Space Illuminant : 0.9642 1 0.82491 Profile Creator : Hewlett-Packard Profile ID : 0 Profile Copyright : Copyright (c) 1998 Hewlett-Packard Company Profile Description : sRGB IEC61966-2.1 Media White Point : 0.95045 1 1.08905 Media Black Point : 0 0 0 Red Matrix Column : 0.43607 0.22249 0.01392 Green Matrix Column : 0.38515 0.71687 0.09708 Blue Matrix Column : 0.14307 0.06061 0.7141 Device Mfg Desc : IEC http://www.iec.ch Device Model Desc : IEC 61966-2.1 Default RGB colour space - sRGB Viewing Cond Desc : Reference Viewing Condition in IEC61966-2.1 Viewing Cond Illuminant : 19.6445 20.3718 16.8089 Viewing Cond Surround : 3.92889 4.07439 3.36179 Viewing Cond Illuminant Type : [D50](https://archive.blender.org/developer/D50) Luminance : 76.03647 80 87.12462 Measurement Observer : CIE 1931 Measurement Backing : 0 0 0 Measurement Geometry : Unknown Measurement Flare : 0.999% Measurement Illuminant : [D65](https://archive.blender.org/developer/D65) Technology : Cathode Ray Tube Display Red Tone Reproduction Curve : (Binary data 2060 bytes, use -b option to extract) Green Tone Reproduction Curve : (Binary data 2060 bytes, use -b option to extract) Blue Tone Reproduction Curve : (Binary data 2060 bytes, use -b option to extract) DCT Encode Version : 100 APP14 Flags 0 : [14] APP14 Flags 1 : (none) Color Transform : YCbCr Image Width : 8031 Image Height : 5906 Encoding Process : Baseline DCT, Huffman coding Bits Per Sample : 8 Color Components : 3 Y Cb Cr Sub Sampling : YCbCr4:4:4 (1 1) Image Size : 8031x5906 Megapixels : 47.4 Thumbnail Image : (Binary data 10592 bytes, use -b option to extract)** ![sample1.jpg](https://archive.blender.org/developer/F10041452/sample1.jpg) ![sample1.PSD](https://archive.blender.org/developer/F10041446/sample1.PSD)
Author

Tried with the latest Blender versions same result.
image.png

Tried with the latest Blender versions same result. ![image.png](https://archive.blender.org/developer/F10041494/image.png)
Member

Vector((2834.645751953125, 2834.645751953125)) means blender is reading it like 72dpi (2834.64 pixels per meter = 72 pixels per inch).

libjpeg reports the density_unit as zero (unknown), it then defaults to 72dpi.
If I save the same image in Krita or Gimp, I get the density_unit correctly reported as one (dots/inch) , X_density / Y_density as 300 and everything behaves as expected.

What library are you parsing the metadata with?
I think there is not much we can do (except use a different library? or somehow read this differently?)

`Vector((2834.645751953125, 2834.645751953125))` means blender is reading it like 72dpi (2834.64 pixels per meter = 72 pixels per inch). libjpeg reports the `density_unit` as `zero` (unknown), it then defaults to 72dpi. If I save the same image in Krita or Gimp, I get the `density_unit` correctly reported as `one` (dots/inch) , `X_density` / `Y_density` as 300 and everything behaves as expected. What library are you parsing the metadata with? I think there is not much we can do (except use a different library? or somehow read this differently?)
Philipp Oeser changed title from bpy.data.images.load => return wrong image resolution to wrong image resolution (dpi) reported for certain jpg files from Photoshop 2021-04-27 13:39:07 +02:00
Member

Changed status from 'Needs User Info' to: 'Confirmed'

Changed status from 'Needs User Info' to: 'Confirmed'
Member

Will keep as a Known Issue for now (would still be nice to know what library is used to (successfully) parse the metadata

Will keep as a Known Issue for now (would still be nice to know what library is used to (successfully) parse the metadata
Author

Dear Philipp,

The library used is quite old and probably well know done by Phil Harvey and also exists as executable sw - ExifTool.

Thanks a lot for your detailed explanation and feedback.

The Original problem is coming from the following scenario when I am trying to calculate the proper image scale:

def get_image_scale(img, blender_object_width_in_cm, blender_object_height_in_cm):
    #get pixel per meter
    img_ppm_hor, img_ppm_ver = img.resolution
    #get size of the image in pixels
    w, h = img.size
    .
Do some job here.
    .

    #calculate proper scaling
    scale_x = blender_object_width_in_cm / img_width_in_cm
    scale_y = blender_object_height_in_cm / img_height_in_cm
    return scale_x, scale_y

In this case, as I mentioned (and you explained as well) Blender will return 72DPI instead of 300, and the image scale will be calculated wrong.
image.png

Any way thanks for your help and support.

Dear Philipp, The library used is quite old and probably well know done by Phil Harvey and also exists as executable sw - ExifTool. Thanks a lot for your detailed explanation and feedback. The Original problem is coming from the following scenario when I am trying to calculate the proper image scale: ``` def get_image_scale(img, blender_object_width_in_cm, blender_object_height_in_cm): #get pixel per meter img_ppm_hor, img_ppm_ver = img.resolution #get size of the image in pixels w, h = img.size . Do some job here. . #calculate proper scaling scale_x = blender_object_width_in_cm / img_width_in_cm scale_y = blender_object_height_in_cm / img_height_in_cm return scale_x, scale_y ``` In this case, as I mentioned (and you explained as well) Blender will return 72DPI instead of 300, and the image scale will be calculated wrong. ![image.png](https://archive.blender.org/developer/F10041669/image.png) Any way thanks for your help and support.
Philipp Oeser removed the
Interest
Core
label 2023-02-09 14:43:12 +01:00
Sign in to join this conversation.
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset Browser
Interest
Asset Browser Project Overview
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
Interest
EEVEE & Viewport
Interest
Freestyle
Interest
Geometry Nodes
Interest
Grease Pencil
Interest
ID Management
Interest
Images & Movies
Interest
Import Export
Interest
Line Art
Interest
Masking
Interest
Metal
Interest
Modeling
Interest
Modifiers
Interest
Motion Tracking
Interest
Nodes & Physics
Interest
OpenGL
Interest
Overlay
Interest
Overrides
Interest
Performance
Interest
Physics
Interest
Pipeline, Assets & IO
Interest
Platforms, Builds & Tests
Interest
Python API
Interest
Render & Cycles
Interest
Render Pipeline
Interest
Sculpt, Paint & Texture
Interest
Text Editor
Interest
Translations
Interest
Triaging
Interest
Undo
Interest
USD
Interest
User Interface
Interest
UV Editing
Interest
VFX & Video
Interest
Video Sequencer
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
Legacy
Blender 2.8 Project
Legacy
Milestone 1: Basic, Local Asset Browser
Legacy
OpenGL Error
Meta
Good First Issue
Meta
Papercut
Meta
Retrospective
Meta
Security
Module
Animation & Rigging
Module
Core
Module
Development Management
Module
EEVEE & Viewport
Module
Grease Pencil
Module
Modeling
Module
Nodes & Physics
Module
Pipeline, Assets & IO
Module
Platforms, Builds & Tests
Module
Python API
Module
Render & Cycles
Module
Sculpt, Paint & Texture
Module
Triaging
Module
User Interface
Module
VFX & Video
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Priority
High
Priority
Low
Priority
Normal
Priority
Unbreak Now!
Status
Archived
Status
Confirmed
Status
Duplicate
Status
Needs Info from Developers
Status
Needs Information from User
Status
Needs Triage
Status
Resolved
Type
Bug
Type
Design
Type
Known Issue
Type
Patch
Type
Report
Type
To Do
No Milestone
No project
No Assignees
2 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: blender/blender#87857
No description provided.