简体   繁体   English

使用 Python 在 Maya 中调整图像大小

[英]Resize images in Maya with Python

I'm pretty new to coding in general.总的来说,我对编码很陌生。 I want a script that could batch process images inside Maya.我想要一个可以在 Maya 中批量处理图像的脚本。 The process should be simple: open an image from a given path folder, resize it, overwrite it.这个过程应该很简单:从给定的路径文件夹中打开一个图像,调整它的大小,覆盖它。

I know PIL should be able to do that, however it appears so it's not supported since Maya 2014 or something.我知道 PIL 应该能够做到这一点,但是它似乎自 Maya 2014 或其他版本以来不受支持。 I've tried the code in Maya 2012 and it works but since I want my code to be accessible to all, I want to find a workaround.我已经尝试过 Maya 2012 中的代码并且它有效,但是由于我希望所有人都可以访问我的代码,因此我想找到一种解决方法。

I'm aware someone re-released a module so it can be supported on more recent builds (on windows only though).我知道有人重新发布了一个模块,因此它可以在更新的版本中得到支持(尽管仅在 Windows 上)。

http://mistermatti.wordpress.com/2014/02/04/maya-2014-with-pythons-pil-module/ http://mistermatti.wordpress.com/2014/02/04/maya-2014-with-pythons-pil-module/

But even when I install it in my build, I get this error when attempting to open my file:但即使我在构建中安装它,尝试打开我的文件时也会出现此错误:

open("E:/SoNuchframe000-00000.png")

cannot identify image file无法识别图像文件

I've tried copying the whole module into my own script and it does the same thing.我试过将整个模块复制到我自己的脚本中,它也做同样的事情。

On the side I've also tried the OpenMaya module另一方面,我也尝试过 OpenMaya 模块

    image.readFromFile('E:/SoNuchframe000-00000.png')
    image.resize(2048, 2048, False)
    image.writeToFile('E:/SoNuchframe000-00000.png' + 'Resized.png')

and this gives me an empty image of 12mb (so by the way, if I could keep it compressed, that would be awesome).这给了我一个 12mb 的空图像(顺便说一下,如果我能保持压缩,那就太棒了)。

So now, I've reached the limit of my powers.所以现在,我已经达到了我的力量极限。 What can I do from here?我可以从这里做什么?

You may use QImage.scaled() from PySide/PyQt http://pyqt.sourceforge.net/Docs/PyQt4/qimage.html#scaled您可以使用 PySide/PyQt http://pyqt.sourceforge.net/Docs/PyQt4/qimage.html#scaled 中的QImage.scaled()

from PySide.QtCore import *
from PySide.QtGui import *

picture = QImage(path)
pic_rescaled = picture.scaled(2048, 2048, Qt.KeepAspectRatio)
pic_rescaled.save(path, "PNG")

Should work on any Maya 2014+应该适用于任何 Maya 2014+

You're missing the compression argument within image.writeToFile(path, compression) .您缺少image.writeToFile(path, compression)的压缩参数。 In this case it should be 'png', but in general this should match the extension of the file you loaded originally.在这种情况下,它应该是“png”,但通常这应该与您最初加载的文件的扩展名相匹配。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM