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

Feature request: expose the internal png module (among other things) #365

Open
indianakernick opened this issue Jan 6, 2021 · 1 comment
Labels
I-Minor Issues that would be nice to have fixed, but are the lowest priority T-Feature Requests for a new feature to be added

Comments

@indianakernick
Copy link

For the purposes of input validation, I would like to know the dimensions of the input PNG. Oxipng has this information but doesn't seem to provide any way of accessing it. For my purposes, I only need the width and height but the whole IHDR chunk would be nice. The simplest way to expose this information would probably be to make the png module public. That would make it possible to access PngImage and write code similar to optimize_from_memory.

let deadline = Arc::new(Deadline::new(opts.timeout));

let original_size = data.len();
let mut png = PngData::from_slice(data, opts.fix_errors)?;

// Inspect IHDR or any auxiliary chunk
let ihdr = &png.raw.ihdr;
if ihdr.width != 256 || ihdr.height != 256 {
    // Invalid image size
}

// Run the optimizer on the decoded PNG.
let optimized_output = optimize_png(&mut png, data, opts, deadline)?;
@indianakernick indianakernick changed the title Feature request: expose the internal png module Feature request: expose the internal png module (among other things) Jan 6, 2021
@andrews05
Copy link
Collaborator

andrews05 commented May 1, 2023

@indianakernick It's actually possible to access PngData and other internals currently, by importing them from a hidden module:
use oxipng::internal_tests::PngData
Note that this is obviously not part of the public api and could change or break in any release. It also doesn't include optimize_png, so you may not actually be able to do what you're wanting this way.

Alternatively, you could use the separate png crate (or similar) to read the header info of the png before deciding whether to pass it into to oxipng.

@andrews05 andrews05 added T-Feature Requests for a new feature to be added I-Minor Issues that would be nice to have fixed, but are the lowest priority labels Oct 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
I-Minor Issues that would be nice to have fixed, but are the lowest priority T-Feature Requests for a new feature to be added
Projects
None yet
Development

No branches or pull requests

2 participants