How to set pHYs chunk (DPI) of PNG file

⚓ Rust    📅 2025-04-25    👤 surdeus    👁️ 7      

surdeus

Warning

This post was published 118 days ago. The information described in this article may have changed.

Hello! I'm trying to update the DPI setting of a PNG image by reading an existing file, updating the pHYs chunk, and writing the output to a new file. For example, I'd update the pHYs chunk to x_res=11811, y_res=11811, units=1, with x_res and y_res values depending on what DPI I want.

I've been messing around with the png crate but it seems really complicated and difficult to grasp for what seems like it should be a minor edit. So far I've been trying to figure out how to decode the image, then manually rebuild it row by row and re-encode it. Is there a simpler way to do this?

I looked at the image crate but I couldn't find any way to change the pHYs chunk or DPI settings with that.

1 post - 1 participant

Read full topic

🏷️ rust_feed