Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Maya Python scale picture

Tags:

python

maya

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 )
like image 296
Jim Avatar asked Dec 21 '25 00:12

Jim


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)
like image 71
Amir Afianian Avatar answered Dec 23 '25 12:12

Amir Afianian



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!