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

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 )
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With