[Bf-committers] Adding an alpha channel though Python's image.save()

patrick boelens p_boelens at msn.com
Thu May 9 15:38:55 CEST 2013


Ah, good idea! That way I won't even need to hack it in; thanks!

> Date: Thu, 9 May 2013 10:20:42 +0100
> From: domino at dominodesigns.info
> To: bf-committers at blender.org
> Subject: Re: [Bf-committers] Adding an alpha channel though Python's	image.save()
> 
> I create a temp image to modify the alpha channel on. Something like
> this for adding an opaque alpha channel.
> 
>         img = bpy.data.images.new("Temp",
>             image.size[0],
>             image.size[1],
>             alpha=True)
>         pixels = list(image.pixels)
>         pixels[3::4] = [1.0 for i in range(len(pixels)/4)]
>         img.pixels = pixels
>         # set img.filepath_raw & img.file_format before save
>         img.save()
>         bpy.data.images.remove(img)
> 
> On 05/09/2013 03:18 AM, patrick boelens wrote:
> > Hi Campbell,
> >
> > Thanks for your reply. I already managed to use ImageMagick to add an alpha channel as a work-around, but will try your solution on a future batch, thanks!
> >
> > -Patrick
> >
> >> Date: Thu, 9 May 2013 11:10:26 +1000
> >> From: ideasman42 at gmail.com
> >> To: bf-committers at blender.org
> >> Subject: Re: [Bf-committers] Adding an alpha channel though Python's	image.save()
> >>
> >> This is a limit in the API, and saving at different bit-depths should
> >> be possible,
> >> for a quick workaround you could set scene render settings and use
> >> Image.save_render method (which is intended for render-engine
> >> integration but I think it would work in your case).
> >>
> >> On Thu, May 9, 2013 at 6:06 AM, patrick boelens <p_boelens at msn.com> wrote:
> >>> Hi everyone,
> >>>
> >>> I've run into a bit of a problem here. I want to use Blender for some batch image-processing but found a bug in saving. If the image loaded in does not have an alpha channel, calling image.save() on it will not add one, even if it does show up correctly in the UV/Image Editor. Saving the image manually from the Editor it works, but that kind of defeats the purpose of the batch processing. ;)
> >>>
> >>> Image.save seems to call IMB_saveiff(), while the menu entry seems to call IMAGE_OT_save(). It's a bit too deep in for me to figure out though, any help on getting this to work would be very much appreciated.
> >>>
> >>> Thanks!
> >>> -Patrick
> >>>
> >>> _______________________________________________
> >>> Bf-committers mailing list
> >>> Bf-committers at blender.org
> >>> http://lists.blender.org/mailman/listinfo/bf-committers
> >>
> >>
> >> -- 
> >> - Campbell
> >> _______________________________________________
> >> Bf-committers mailing list
> >> Bf-committers at blender.org
> >> http://lists.blender.org/mailman/listinfo/bf-committers
> >  		 	   		  
> > _______________________________________________
> > Bf-committers mailing list
> > Bf-committers at blender.org
> > http://lists.blender.org/mailman/listinfo/bf-committers
> 
> _______________________________________________
> Bf-committers mailing list
> Bf-committers at blender.org
> http://lists.blender.org/mailman/listinfo/bf-committers
 		 	   		  


More information about the Bf-committers mailing list