Skip to content

Thumbnail: fill with blank/transparent #127

Answered by kipcole9
AntoineAugusti asked this question in Q&A
Discussion options

You must be logged in to vote

Image.thumbnail/3 will primarily aim to keep the aspect ratio of the image. And it will thumbnail so that the longest edge is the size specified. If you add resize: :force then it will fill the bounding box but the aspect ratio of the image will be stretched which I'm pretty sure is not what you want.

The following is what I would suggest. It thumbnails the image and then embeds it in a white background.

{:ok, logo} = 
  "path/to/image"
  |> Image.thumbnail!(100)
  |> Image.embed!(100, 100, background_color: :white)

Let me know how that goes?

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@AntoineAugusti
Comment options

Answer selected by AntoineAugusti
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #126 on January 22, 2024 12:28.