Thumbnail: fill with blank/transparent #127
-
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 |
Beta Was this translation helpful? Give feedback.
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? |
Beta Was this translation helpful? Give feedback.
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 addresize: :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.
Let me know how that goes?