I've been stuck on this for a couple days now, and have tried several image editing techniques in Python and Rust. It seems simple, but I can't find any way to crop a .png without distorting colors across the whole image.
When I run this example script for Rust's image
crate from a tutorial that I can't find any more:
use image::GenericImageView;
fn main() {
// Use the open function to load an image from a Path.
// `open` returns a `DynamicImage` on success.
let img = image::open("../test.png").unwrap();
// The dimensions method returns the images width and height.
println!("dimensions {:?}", img.dimensions());
// The color method returns the image's `ColorType`.
println!("{:?}", img.color());
// Write the contents of this image to the Writer in PNG format.
img.save("../test copy.png").unwrap();
}
The resulting test copy.png
is ~25% smaller and noticeably darker than the original.
I'm looking for a way to crop an image but not make any other change. This is easy to do manually in MS Paint, but is there any way to do it by script?
EDIT: Uploaded .png file and discolored copies to https://github.com/Densaugeo/stack-overflow-question/tree/main