Thumbnail: fill with blank/transparent #127
Answered
by
kipcole9
AntoineAugusti
asked this question in
Q&A
|
Hi, Thanks for this lib 🙏 I have the following code: Mix.install(
[{:image, "~> 0.37"}]
)
{:ok, thumb} = Image.thumbnail("/tmp/divia.jpg", 100, fit: :contain)
Image.write(thumb, "/tmp/divia-small.png")QuestionHow to get a 100x100 image, filled with white/transparent? Source imageGenerated imageSize: 100x38 |
Answered by
kipcole9
Jan 22, 2024
Replies: 1 comment 1 reply
|
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? |
1 reply
Answer selected by
AntoineAugusti
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment


Image.thumbnail/3will 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 addresize: :forcethen 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.
Let me know how that goes?