Maya Python scale picture

Viewed 315

How to scale a picture to fit a window/layout?

enter image description here

With the code below the original image is not actually enlarged to 300px, it is displayed with the original image size instead.

import maya.cmds as cmds

if (cmds.window(window1, exists=True)):
    cmds.deleteUI(window1)

window1 = cmds.window(w=300, h=300)
layout = cmds.columnLayout(w=300, h=300)
cmds.picture( image='image.png', w=300, h=300)

cmds.showWindow( window1 )
1 Answers

Try this

import maya.OpenMaya as om

def resize_image(source_image, output_image, width, height):

    image = om.MImage()
    image.readFromFile(source_image)

    image.resize( width, height )
    image.writeToFile(output_image, 'png')


resizeImage('<source_image.png>','<output_image.png>', 300, 300)
Related