How to export as png an image texture

How can I export an image texture with phyton?

I like something like this:

imgs = bpy.data.images
for image in imgs:
Export(image)

Any idea?
Antonio

is the source image also png, or is it in a different format?

This answer shows how to save an image to an arbitrary path.

The idea is to read all images of a blend file and then export as PNG or JPG as thumbnails. Really the source format is not important, the important is the output file. I want to generate a preview of all textures to create a document with an external tool.

Yes, I have tested this script, but what I want is to take a texture of the blend file and create the output PNG with the same image and size. Maybe, there is any shorcut to save a texture as PNG.

My initial script is this:

import bpy

print("
---------- Image thumbnails ---------------------")
imgs = bpy.data.images
for image in imgs:
name = image.name
# read only 6 first characters
if (name[:6] != “Sprite”):
path = image.filepath
print(">>" + path)

    w = image.size[0]  
    h = image.size[1]  
  
    if (w > 0):
        print('image width: %d' % w)  
        print('image height: %d' % h)      
        try:
            pngimage = bpy.data.images.new("Sprite", alpha=True, width=w, height=h)
            #pngimage = image.copy() 
            pngimage.use_alpha = True
            pngimage.alpha_mode = 'STRAIGHT'
            pngimage.filepath_raw = "C:/tmp/" + name
            pngimage.file_format = 'PNG'
            pngimage.save()   
            print("Saved OK")     
        finally:
            bpy.data.images.remove(pngimage)           

But the PNG is always an empty black image or I get an error if enable image.copy().

1 Like

Thanks CodEmanX, but this example is to save the render image. What I want is create thumbnails of all textures in the blend file. I have done that with Java, but I want to make the same with Phyton to create an Addon.

Example created with Java tool (still in beta phase):


although it reads save_render, it does not save the rendered image!
“Save image to a specific path using a scenes render settings”

It saves the image using the render settings (fileformat, color mode and depth etc., filepath is overwritten by save_render parameter though; dimension-related options seem to be ignored, e.g. render resolution)

Thanks, it works. :yes:

Sorry, it was my fault not test your code and only read the sentences.

BTW, do you know how can I resize the output Image?

I haven’t come across a resize feature yet, maybe see if psy-fi added something in his branch. Maybe just call an external tool that supports various interpolation algorithms.