olxgroup-oss / libvips-rust-bindings

Rust bindings for libvips
MIT License
95 stars 41 forks source link

Issue with `thumbnail_with_opts` #42

Open GamerBene19 opened 1 year ago

GamerBene19 commented 1 year ago

I'm trying to resize an image based on height and width. If I use thumbnail (only using width) it works as intended, using thumbnail_with_opts it does not. Note that I have moved the App into the function to be able to access the error buffer.

fn manipulate_image(path: &str, height: i32, width: i32, quality: u32) -> Result<(), ()> {
    let libvips = VipsApp::new("app", true).expect("Could not start libvips");
    libvips.concurrency_set(2);

    // TODO: Error handling
    let thumb_opts = ops::ThumbnailOptions {
        height: height,
        ..ops::ThumbnailOptions::default()
    };
    log::info!("{}", path);
    // This works
    // let image = ops::thumbnail(&path, width).unwrap();
    // This doesn't
    let image: VipsImage = match ops::thumbnail_with_opts(path, width, &thumb_opts) {
        Err(err) => {
            log::error!("{}", err);
            log::error!("{}", libvips.error_buffer().unwrap());
            return Err(());
        }
        Ok(img) => img,
    };

    image.image_write_to_file("uploads/temp.jpg").unwrap();
    return Ok(());
}

I do get the following error (the path from above does exist)

vips error: ThumbnailError. Check error buffer for more details
vips__file_read: error reading from file ""
    profile_load: unable to load profile ""
    vips__file_read: error reading from file ""
    profile_load: unable to load profile ""

vips_threadset_free: peak of 0 threads
memory: high-water mark 1.35 MB
error buffer: vips__file_read: error reading from file ""
profile_load: unable to load profile ""
vips__file_read: error reading from file ""
profile_load: unable to load profile ""

Am I doing something wrong? If so please tell me what the correct way is.

psytraxx commented 1 year ago

i experienced a similar issue my fix was to add

import_profile: "sRGB".into(), export_profile: "sRGB".into(),

to &ops::ThumbnailImageOptions

GamerBene19 commented 1 year ago

i experienced a similar issue my fix was to add

import_profile: "sRGB".into(), export_profile: "sRGB".into(),

to &ops::ThumbnailImageOptions

That worked. Thank you very much!