discuitnet / discuit

A free and open-source community discussion platform.
https://discuit.net
GNU Affero General Public License v3.0
411 stars 52 forks source link

[Enhancement] Image scaling/Handling of 'Tall' Images #72

Open JackIsAlive opened 4 months ago

JackIsAlive commented 4 months ago

Current State: Images of a small, tall resolution are not displayed correctly. This may simply be due to the small image size, not necessarily the resolution. Embeds of the post link dispaly the full image. image image

Future State: Images of 'Tall' resolutions, roughly 9:16, are displayed correctly. Consideration needs to be made for obnoxiously tall posts, in such a case it may be beneficial to enforce a max height and allow a user to click into an image to view the full image within another tab.

Justification: Certain posts are cropped on site and when inspecting the image itself resulting in an issue with creating 'tall' contnt.

Acceptance Criteria:

TylerCode commented 4 months ago

I want to add that this has been very inconsistent for me. It may be anecdotal but I've had a few times where it seemed like an image SHOULD have been cut off and it wasn't.

reallytiredofclowns commented 3 months ago

This appears to be fixed by changing the ImageFitCover arguments to ImageFitContains on my local dev copy.

core/post.go

        for _, post := range imagePosts {
            if post.ID == postID {
                img := record.Image()
                img.PostScan()
                img.AppendCopy("tiny", 120, 120, images.ImageFitCover, "")
                img.AppendCopy("small", 325, 250, images.ImageFitCover, "")
                img.AppendCopy("medium", 720, 1440, images.ImageFitContain, "")
                img.AppendCopy("large", 1080, 2160, images.ImageFitContain, "")
                img.AppendCopy("large", 2160, 4320, images.ImageFitContain, "")
                post.Image = img
                break
            }
        }

Link to original image for testing.

I'm not 100% certain how the image scaling is handled at this point, so if anyone is brave enough to make PR, it'd be great to fix this long-standing bug. Otherwise I'll slowly work my way through the code to see if the fix makes sense.