Results 1 to 6 of 6
  1. #1

    Saving a newly created image

    Hi !

    I'm having a bit of trouble with a quite simple process : i'd like to create and save an image file only with python. To create an image, it's fairly easy :
    Code:
    bpy.ops.image.new('my_image')
    But when it comes to saving it, none of those works :
    Code:
    bpy.ops.image.save_as(filepath='my_image')
    Code:
    img = bpy.data.images['my_image']
    img.save_render(filepath='my_image')
    And of course none of those :
    Code:
    bpy.ops.image.save()
    Code:
    img = bpy.data.images['my_image']
    img.save()
    And I haven't found in the API doc another way to save an image. How can I do that ?

    Thanks a lot !

    (I'm using Blender 2.63)
    Last edited by kevar; 14-Sep-12 at 09:05.



  2. #2
    there's a few states in which an imagine can be
    - you can make a new image ( bpy.ops.image.new('my_image') ) | type='UV_TEST'
    - you can render an image ( ['Render Result'] unless you rename it ) | type='RENDER_RESULT'
    - an image can be loaded from an external source. | type='IMAGE'

    An image of type uv test ( ie, new image ) , you must set the filepath_raw and file_format first
    Code:
    bpy.data.images['my_image'].filepath_raw = '/tmp/hoopla.png'
    bpy.data.images['my_image'].file_format = 'PNG'
    bpy.data.images['my_image'].save()
    save_render only works with renders.
    Last edited by zeffii; 17-Sep-12 at 08:37.



  3. #3
    OK, I better understand how it works now. Thanks !



  4. #4
    There is a slight problem with my suggestion, if you create an image from blender the type is TGA / TARGA, when you use my suggestion it will save the image as a .png but it will actually be a .TGA. and it will produce files that image editors aren't expecting. I'm still looking into it, because i use this method for my image uploader too.

    you have to do
    Code:
    bpy.data.images['my_image'].filepath_raw = '/tmp/hoopla.png'
    bpy.data.images['my_image'].file_format = 'PNG'
    bpy.data.images['my_image'].save()
    Last edited by zeffii; 14-Sep-12 at 10:19.



  5. #5
    Member
    Join Date
    Dec 2011
    Location
    Germany
    Posts
    1,234
    zeffii: what was the original code of your post #2?
    http://blenderartists.org/forum/show...=1#post2203969

    just without setting file_format?



  6. #6
    CoDEmanX, Yeah, not setting the file_format to the same as the filepath_raw extension isn't a good idea.



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •