0
$\begingroup$

I am adding to an add-on and I am trying to take the image in the active material node, make a backup of the original, and then with two different scripts, resize it, and convert it to JPEG.

Example: In the active object's material, there is a 4k image attached to the diffuse, and a 4k image in the roughness input.

The user can select the diffuse image, click a button to resize it to 2k, then click on roughness image, click a button and resize it to 1024x1024 and then click another button to convert it to JPEG, automatically saving a backup, loading the new version and refreshing all modified images.

I was able to figure out how to resize, save and refresh all those images, but it overwrites the original, uses ops to save and I still don't know how to convert it to jpeg.

image = bpy.context.active_object.active_material.node_tree.nodes.active.image
image.scale(512,512)

bpy.ops.image.save_all_modified()

for image in bpy.data.images:
    image.reload()
$\endgroup$
1
$\begingroup$

Try

image.file_format = 'JPEG'
image.filepath_raw = your_new_filepath_here
image.save()
$\endgroup$
1
  • $\begingroup$ This worked, thanks! I was able to use this and then fill in some of the gaps. Still developing it, but this was the biggest missing puzzle piece for me. $\endgroup$ Apr 4 at 17:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.