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

Add an option so that image resizes up not only down #59

Open
TadoTheMiner opened this issue Nov 20, 2024 Discussed in #58 · 3 comments
Open

Add an option so that image resizes up not only down #59

TadoTheMiner opened this issue Nov 20, 2024 Discussed in #58 · 3 comments

Comments

@TadoTheMiner
Copy link

The fact that in #58 the image doesn't resize is a feature not a bug. Therefore I think there should be a way to set so that the image resizes to fit the render area, even if the image is already in the full size. I suggest adding an always_resize field into the widget which will be set by a function with the same name. (or add it to the resize function though that will be a breaking change)

@benjajaja
Copy link
Owner

Looks like a DPI issue, not sure if this should be handled by the lib right now.

@TadoTheMiner
Copy link
Author

I don't think DPI is related to my issue.

fn render_area(rect: Rect, area: Rect, overdraw: bool) -> Option<Rect> {
    if overdraw {
        return Some(Rect::new(
            area.x,
            area.y,
            min(rect.width, area.width),
            min(rect.height, area.height),
        ));
    }

    if rect.width > area.width || rect.height > area.height {
        return None;
    }
    Some(Rect::new(area.x, area.y, rect.width, rect.height))
}

If I understood the code properly rect (i think there should be a more descriprive name) is the image area, and area is the area the image should render to. If there is no overdraw, the image doesn't get resized at all - it's width and height is returned. What I am asking for is to edit the function that if the user of the library has set that they want to always resize the image, the function calculates the width and height so that the image resizes as much as it can, preserving the aspect ratio.

@benjajaja
Copy link
Owner

benjajaja commented Nov 20, 2024

Yes, DPI is directly related to the issue, however there could also be a different resize option to scale the image. Resize::Scale or something like that, with an option to keep proportion. This would indirectly solve the DPI problem, however it would also "overscale" small images if the terminal is big.

AFAIK, modern GUIs work with whatever DPI settings there are: wayland, x11, gnome, kde, all have different opinions on DPI. For example, I can scale with wayland on my machine, but then not every program might pick up this scale to display high density. Firefox and gimp do pick it up. When I take a screenshot with the same image displayed side by side in Firefox and with ratatui-image (Firefox' image is about 1.5 times the size as ratatui-image's), the resulting screenshot is actually bigger than my resolution, the image in ratatui-image is displayed exactly at the image pixel size, and the Firefox image is scaled up.

If you're up to it, go ahead and try adding something like Resize::Scale(keep_proportion) (or without the proportion option, until someone actually needs it).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants