0

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

Densaugeo
  • 55
  • 3
  • 1
    This is the same problem as your [previous question](https://stackoverflow.com/q/76451671/7328782). You’re using a different language, but the language is not the problem. Your input PNG files are the problem, as commented on the other post. If you want help with this you need to post one of your PNG files, in a way that doesn’t change them (imgur will convert them if they’re large). – Cris Luengo Jun 12 '23 at 01:42
  • Thanks, I've now uploaded the test .png file to a git repo: https://github.com/Densaugeo/stack-overflow-question/tree/main . – Densaugeo Jun 12 '23 at 02:12

0 Answers0