Just use 

myPalette := append(palette.WebSafe, image.Transparent)


You can't add transparent color to plan9 palette since it's already full. 
Better to use WebSafe!


On Friday, 4 December 2015 14:05:56 UTC+5:30, Brian Picciano wrote:
>
> Ah, good call. So I've replaced the encode/decode nonsense with that and 
> things still work. Except transparency still isn't working :(
>
> Here is the function in question, the ctx simply holds onto a bunch of the 
> values, like the final gif.GIF being created and such:
>
> func (c *ctx) addFrame(img image.Image) error { 
>         opts := gif.Options{ 
>                 NumColors: 256, 
>                 Drawer:    draw.FloydSteinberg, 
>         } 
>         b := img.Bounds() 
>  
>         // More or less taken from the image/gif package 
>         pimg := image.NewPaletted(b, palette.Plan9[:opts.NumColors]) 
>         if opts.Quantizer != nil { 
>                 pimg.Palette = opts.Quantizer.Quantize(make(color.Palette, 
> 0, opts.NumColors), img) 
>         } 
>         opts.Drawer.Draw(pimg, b, img, image.ZP) 
>  
>         spf := 1 / float64(c.fps) 
>  
>         c.g.Image = append(c.g.Image, pimg) 
>         c.g.Delay = append(c.g.Delay, int(spf*100)) 
>         return nil 
> }
>
>
>
> On Friday, December 4, 2015 at 1:19:35 AM UTC-7, Caleb Spare wrote:
>>
>> I'm not sure about the transparency thing. 
>>
>> In order to transform your image.Images into *image.Paletted, you can 
>> do what the gif encoder does. The code is very short: 
>>
>> https://github.com/golang/go/blob/master/src/image/gif/writer.go#L358-L366 
>>
>> (Basically, check if it's already an *image.Palleted; if not, use a 
>> quantizer to re-render it as a paletted image.) 
>>
>> -Caleb 
>>
>> On Thu, Dec 3, 2015 at 11:33 PM, Brian Picciano 
>> <mediocr...@gmail.com> wrote: 
>> > Hi there! I'm currently attempting to make a gif out of a series of 
>> > image.Image instances (each the same dimensions). I see that to build 
>> the 
>> > gif.GIF struct I need to somehow turn my image.Images into 
>> *image.Paletted, 
>> > but after browsing the various image apis I still don't see an obvious 
>> way 
>> > to do that. Currently I'm using gif.Encode to encode a single frame 
>> into a 
>> > buffer, then gif.DecodeAll to decode it back out into its own gif.GIF, 
>> and 
>> > then append that to my actual gif. This is super ugly and feels very 
>> wrong, 
>> > and it also seems to break transparency. Any help would be appreciated, 
>> > thanks! 
>> > 
>> > -- 
>> > You received this message because you are subscribed to the Google 
>> Groups 
>> > "golang-nuts" group. 
>> > To unsubscribe from this group and stop receiving emails from it, send 
>> an 
>> > email to golang-nuts...@googlegroups.com. 
>> > For more options, visit https://groups.google.com/d/optout. 
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/9751ae4c-6853-4c32-986e-3466a038e6af%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to