Git Product home page Git Product logo

Comments (6)

paolobarbolini avatar paolobarbolini commented on September 26, 2024

The difference is probably a result of the image getting decoded and re-encoded using different settings or different encoders, which while all producing PNG compliant images may embed different attributes into the image or use different compression algorithms or settings.

from image.

Mon-ius avatar Mon-ius commented on September 26, 2024

But the the original image source is png, there should no such encode, decode proccess performed to cause such issue.

I have another code can be assessed

        let _raw = std::fs::read(&url)?;
        let img = ImageReader::with_format(Cursor::new(&_raw), image::ImageFormat::Png).decode()?;
        let mut buf: Vec<u8> = Vec::new();
        img.write_to(&mut Cursor::new(&mut buf), image::ImageOutputFormat::Png)?;
        let _b64 = BASE64.encode(&buf);

However, it produce same base64 result

from image.

paolobarbolini avatar paolobarbolini commented on September 26, 2024

ImageReader::open is decoding the image. write_to is re-encoding it.

from image.

Mon-ius avatar Mon-ius commented on September 26, 2024

Did not find a way to prevent such proccess so far, the direct way as "https://www.reddit.com/r/rust/comments/11hyeau/help_cant_correctly_encode_an_image_to_base64" described caused an error.

from image.

Mon-ius avatar Mon-ius commented on September 26, 2024

ImageReader::open is decoding the image. write_to is re-encoding it.

@paolobarbolini Now the question becomes, fill the blank code snippet ;)

let base_img = image::open(url)?;
# convert the `base_img` into [u8] buffer, without encoding-decoding
let _b64 = BASE64.encode(&buf);

from image.

Mon-ius avatar Mon-ius commented on September 26, 2024

Okay, f**k image crate;

        let _buf = std::fs::read(&_url)?;
        let _b64 = BASE64.encode(&_buf);

Just solved it :P

from image.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.