Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

image/png: no support for setting and retrieving the PPI/DPI #18365

dmoklaf opened this issue Dec 17, 2016 · 7 comments

image/png: no support for setting and retrieving the PPI/DPI #18365

dmoklaf opened this issue Dec 17, 2016 · 7 comments
FeatureRequest help wanted NeedsFix The path to resolution is known, but the work has not been done.


Copy link

dmoklaf commented Dec 17, 2016

Please answer these questions before submitting your issue. Thanks!

What version of Go are you using (go version)?

go1.7.4 darwin/amd64

What operating system and processor architecture are you using (go env)?

GOPATH="/Users/raphaelgeronimi/Local/Others/Go workspace"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/zw/0zvr11l11975vn4gk7s4hrx00000gn/T/go-build732769753=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

I need to mass-produce PNG chart images in high resolution - i.e., PPI at 2x-4x multiple of the default 72 value

What did you expect to see?

A new encoding method and/or an Options field to customize the PPI of the image being encoded. Similarly, extending the image.Config struct to be able to retrieve the PPI of a decoded image.

What did you see instead?

No method found.

I wrote a patch with the missing code. However the public API design needs to be discussed first as a "clean" API - i.e., adding an Options field to the Encode function to perfectly mirror the design of image/jpeg - is unfeasible as it would break the Go 1 compatibility

Copy link

dsnet commented Dec 17, 2016

/cc @nigeltao

@dsnet dsnet added this to the Unplanned milestone Dec 20, 2016
Copy link

dmoklaf commented Dec 21, 2016

The proposal is the following:

(1) In image/png:
Define Options as

type Options struct {
    PPI int

EncodeOptions(w io.Writer, m image.Image, **o Options**) error
which would perform the same encoding as Encode(...), plus encode the PPI into the PNG file
Modify the Decode(...) function so that it also returns the PPI into the image.Config result

(2) In image:
Extend the image.Config struct with a new field:
PPI int

What would be left out of my patch is the corresponding PPI support in the image/jpeg library (my project only uses the image/png library). image/gif requires no patches as GIFs do not support PPI.

Copy link

Specifically, the type should probably be called EncodeOptions, to allow us to to define a DecodeOptions at some point (e.g. to specify a destination buffer). That would mean renaming the function to something else, possibly EncodeImage.

Generally, though, PPI is just one example of image metadata, such as EXIF fields (e.g. #4341). There's a discussion of image metadata at #5050, but there's no concrete API proposal yet. I'd rather solve the general problem than specifically adding a PPI mechanism.

Copy link

dmoklaf commented Dec 22, 2016

I agree this is only a subpart of the metadata issue.

Copy link

How to solve?

Copy link

hey @dmoklaf did your solution work/can i access it? I really need to generate some images with a higher value than the 72 default. I also wonder why this functionality still has not been added to the images package yet?

Copy link

dmoklaf commented Mar 14, 2022

Hi, we finally didn't control the PPI, rather controlling instead the resolution of the image (in pixels) and its display width (with HTML/CSS). I may be wrong but it seems this library has only undergone mandatory Go maintenance (to support changes in other Go libs). This is unfortunate as the code is excellent and not much is needed to make it cutting edge.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
FeatureRequest help wanted NeedsFix The path to resolution is known, but the work has not been done.
None yet

No branches or pull requests

6 participants