Aspect ratio, cropping and resizing #76
Replies: 3 comments
-
Oh, and I forgot to mention. I've been looking into the animation frames in the kitty documentation. Since it allows for frames to made by composing smaller images, I believe there is a way to use control keys |
Beta Was this translation helpful? Give feedback.
-
Thank you so much for all the effort you've put into this, this is amazing research! Not having to write the resized variants to disk would also be super amazing, I try not to think about how many files we create as it makes me cringe and be ashamed. I'll look into Thanks again for all the work! |
Beta Was this translation helpful? Give feedback.
-
I've done some testing on ways the kitty protocol can be used directly to provide scaling (both suggested in #22 ) which retains aspect ratio. These both utilize the calls to display the image so only require 1 transmit call to provide all the scaling. I wanted to look into ways to minimize the temp files that get created. The first way uses the padding values The second method uses transparent padding on the input image which is cropped as required to maintain the aspect ratio of the image. Scaling is also achieved by using aspect_and_scaling.mp4What is the best way to approach this? I think the second is more desireable since the consistent location obviously makes it smoother, however, in the first one, there is no padding requirements, so will be more scalable. |
Beta Was this translation helpful? Give feedback.
-
As mentioned in #22, the current implementation forces images to align with the grid. I don't have any experience with ueberzug, however, with kitty I don't believe this is strictly necessary.
The current implementation uses in 'renderer.lua' uses
width
andheight
as the target bounding box for the image. When resizing using magick, this bounding box is used as the exact size for resize. I've written a script to change the width/height on the fly to set a bounding box. Only one value is set in the image so the other is calculated by 'renderer.lua'. Below is the result from changing the size with the implementation as-is (with crop turned off in kitty features):asis.mp4
Unsurprisingly, the aspect ratio changes when the image is resized. Compare that to below:
preserve_aspect.mp4
The change I made was during resize (code on the right, pls ignore how bad it is for now). It assumes that forcing the aspect ratio is always desired. Assuming the image will not by default conform to the grid, there are 2 options for resizing, enforcing pixel-width or height. Only one of these will fit entirely within the bounding box. After determining which to enforce, the other value can be calculated as being the resolution which best preserves the aspect ratio. I haven't setup a PR because I'm hoping to get some feedback first about what the most appropriate solution is.
Additionally, I've been experimenting with ways to efficiently scale images on the fly, which got me looking into the kitty protocol more heavily. Using control keys
c
andr
when displaying, shrinks or expands the displayed image to fit within that rectangle. Since these values do have to conform to the terminal grid, this would still break the aspect ratios and resizing as above, however, may mean we don't strictly need to use temp files.I'm curious if anyone has thoughts on how this should be handled. Any thoughts on this would be great!
Beta Was this translation helpful? Give feedback.
All reactions