我的脚本有什么问题,将 psd 导出到 bmp?
what is wrong with my script, export psd to bmp?
我正在尝试将我的 psd 文件导出为 bmp。
如果我在 ###here 删除一行,它会正确地生成 test.png,
但我想获取 bmp 文件,
如果我使用 ###here ,我会得到 "AttributeError: Property 'Photoshop.BMPSaveOptions.Format' can not be set."
import win32com.client
import os
fn='test.psd'
psApp = win32com.client.Dispatch('Photoshop.Application')
options = win32com.client.Dispatch('Photoshop.ExportOptionsSaveForWeb')
options.Format = 13 # PNG
options.PNG8 = False # Sets it to PNG-24 bit
#options = win32com.client.Dispatch('Photoshop.BMPSaveOptions') ###here del
#options.Format = 2 # bmp
#
fd=os.path.abspath('.')
fk=os.path.join(fd, fn)
doc = psApp.Open(fk)
fn='BBB'
fn = os.path.splitext(fk)[0] + '_' + fn + '.png'
#fn = os.path.splitext(fk)[0] + '_' + fn + '.bmp' ###
doc.Export(ExportIn=fn, ExportAs=2, Options=options) #ExportAs=2,
doc.Close(2)
如果我正确地阅读了你的问题(如果我没有正确阅读,请见谅)你想将文件保存为 BMP 而不是 PNG 格式。我猜你需要更改 options.Format
options.Format = 13 # PNG
经过一些研究,BMP 看起来是 2 所以我将您的代码更改为:
options.Format = 2 # BMP
请注意,我还建议您在保存文件时更改文件名以避免混淆。也许是这个?
fn = os.path.splitext(fk)[0] + '_' + fn + '.bmp'
我正在尝试将我的 psd 文件导出为 bmp。
如果我在 ###here 删除一行,它会正确地生成 test.png, 但我想获取 bmp 文件,
如果我使用 ###here ,我会得到 "AttributeError: Property 'Photoshop.BMPSaveOptions.Format' can not be set."
import win32com.client
import os
fn='test.psd'
psApp = win32com.client.Dispatch('Photoshop.Application')
options = win32com.client.Dispatch('Photoshop.ExportOptionsSaveForWeb')
options.Format = 13 # PNG
options.PNG8 = False # Sets it to PNG-24 bit
#options = win32com.client.Dispatch('Photoshop.BMPSaveOptions') ###here del
#options.Format = 2 # bmp
#
fd=os.path.abspath('.')
fk=os.path.join(fd, fn)
doc = psApp.Open(fk)
fn='BBB'
fn = os.path.splitext(fk)[0] + '_' + fn + '.png'
#fn = os.path.splitext(fk)[0] + '_' + fn + '.bmp' ###
doc.Export(ExportIn=fn, ExportAs=2, Options=options) #ExportAs=2,
doc.Close(2)
如果我正确地阅读了你的问题(如果我没有正确阅读,请见谅)你想将文件保存为 BMP 而不是 PNG 格式。我猜你需要更改 options.Format
options.Format = 13 # PNG
经过一些研究,BMP 看起来是 2 所以我将您的代码更改为:
options.Format = 2 # BMP
请注意,我还建议您在保存文件时更改文件名以避免混淆。也许是这个?
fn = os.path.splitext(fk)[0] + '_' + fn + '.bmp'