I am trying to draw multiple transparent images to form a big one and save it as PNG
func generateUserImage(username string, items []models.Item) error {
imageFile, err := os.Create("public/items/users/" + username + ".png")
if err != nil {
return err
}
profileImage := image.NewRGBA(image.Rect(0, 0, 261, 336))
for _, item := range items {
revel.INFO.Println(item)
itemFile, err := os.Open("public/items/universe/" + item.Type + "/" + item.Name + ".png")
if err != nil {
return err
}
itemImage, err := png.Decode(itemFile)
if err != nil {
return err
}
draw.Draw(profileImage, profileImage.Bounds(), itemImage, image.Point{0, 0}, draw.Src)
itemFile.Close()
}
err = png.Encode(imageFile, profileImage)
if err != nil {
return err
}
defer imageFile.Close()
return nil
}
Everything seems to be working fine except that the final image will only contain the LAST image of the range loop (even tho the range loops 5 times). All images are .png and with transparent background. Here is a demo on how images look
You can try to save the image and see that the background is transparent... So I have no idea why the final image only contains 1 image and not all
Thanks
As mentioned in the comments.
draw.Draw(profileImage, profileImage.Bounds(), itemImage, image.Point{0, 0}, draw.Over)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With