Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

JPEG dpi read from EXIF uses XResolution for both axes

未关闭
#10,331 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

@unvisible789 已经在做这个了。

开始于 2026年10月27日。

  • #10334 来自 @unvisible789 —— 未关闭

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
20/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
停滞
技术栈
python
领域
backend

调研方向

The issue identifies _read_dpi_from_exif as the entry point but gives no file path or test location. Read that function and the JPEG DPI tests, then run the relevant tests with EXIF XResolution 300 and YResolution 150 while JFIF is absent. Done means the reported DPI preserves both axes as (300.0, 150.0); linked PR #10334 is already open.

由索引模型根据 Issue 内容生成。

描述

What did you do?

I'm building an image-optimization tool that prepares screenshots and photos for PDFs: it picks the output format, carries the DPI so pages place at the right size, and checks that lossless steps keep every pixel. Its test suite generates each input type Pillow opens and runs it through the tool, which is where this came up. A JPEG whose resolution is only in EXIF, XResolution 300 and YResolution 150, came back square.

import io
from PIL import Image

exif = Image.Exif()
exif[0x011A] = 300.0  # XResolution
exif[0x011B] = 150.0  # YResolution
exif[0x0128] = 2      # ResolutionUnit: inches
buf = io.BytesIO()
Image.new("RGB", (16, 16)).save(buf, "JPEG", exif=exif)

# Pillow writes a JFIF APP0 segment with units 0; drop it so DPI must come from EXIF
data = buf.getvalue()
app0_length = int.from_bytes(data[4:6], "big")
assert data[2:4] == b"\xff\xe0"
data = data[:2] + data[4 + app0_length:]

with Image.open(io.BytesIO(data)) as im:
    print(im.info["dpi"])
What did you expect to happen?

(300.0, 150.0)

What actually happened?

(300.0, 300.0). _read_dpi_from_exif reads only 0x011A (XResolution) and sets (dpi, dpi), so YResolution never applies. The JFIF and TIFF paths report the two axes separately.

Related: #10332 (TIFF dpi with no resolution tags).

What are your OS, Python and Pillow versions?
  • OS: Ubuntu 24.04 (Linux x86_64)
  • Python: 3.13.13
  • Pillow: 13.0.0 (also reproduces on 12.3.0)
--------------------------------------------------------------------
Pillow 13.0.0
Python 3.13.13 (main, May 10 2026, 19:26:54) [Clang 22.1.3 ]
--------------------------------------------------------------------
Python executable is ~/.venv/bin/python
Environment Python files loaded from ~/.venv
System Python files loaded from ~/.local/share/uv/python/cpython-3.13.13-linux-x86_64-gnu
--------------------------------------------------------------------
Python Pillow modules loaded from ~/.venv/lib/python3.13/site-packages/PIL
Binary Pillow modules loaded from ~/.venv/lib/python3.13/site-packages/PIL
--------------------------------------------------------------------
--- PIL CORE support ok, compiled for 13.0.0
--- TKINTER support ok, loaded 9.0
--- FREETYPE2 support ok, loaded 2.14.3
--- LITTLECMS2 support ok, loaded 2.19
--- WEBP support ok, loaded 1.6.0
--- AVIF support ok, loaded 1.4.2
--- JPEG support ok, compiled for libjpeg-turbo 3.2.0
--- OPENJPEG (JPEG2000) support ok, loaded 2.5.4
--- ZLIB (PNG/ZIP) support ok, loaded 1.3, compiled for zlib-ng 2.3.3
--- LIBTIFF support ok, loaded 4.7.2
--- RAQM (Bidirectional Text) support ok, loaded 0.11.0, fribidi 1.0.13, harfbuzz 14.5.0
*** LIBIMAGEQUANT (Quantization method) support not installed
--- XCB (X protocol) support ok
--------------------------------------------------------------------
主要语言
Python
星标
13.9k
派生
2.6k
平均合并
1 天 7 小时
30 天内合并 PR
174

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

python-pillow/Pillow 的其他 Issue

查看 python-pillow/Pillow 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。