将vbScript转换为Python

问题描述 投票:-1回答:1

我有以下程序,我只想使用任何python库(如PIL或Pillow)转换为Python WITHOUT。 Python可以这样做吗?我是python的新手,但有时该语言似乎使用大槌敲打小指甲...

此代码采用4个参数并裁剪图像;我尝试使用PIL,但是由于我是在锁定代理中工作的,因此出现错误,提示它无法导入库。

即使可以,我真的不想只是为了执行以下代码而导入数百行代码。

Option Explicit

Dim lngWidth, lngHeight, lngBottomCrop
Dim objShell, objArgs, objXmlHttp, objStream, objImageFile, objImageProcess, objFSO, objFile
Dim strImageURL, strImageFile

Set objShell = CreateObject("WScript.Shell")
Set objFSO = CreateObject("Scripting.FileSystemObject")

Set objArgs = WScript.Arguments
strImageURL = objArgs.Item(0)
strImageFile = objArgs.Item(1)
lngWidth = CLng(objArgs.Item(2))
lngHeight = CLng(objArgs.Item(3))

Set objXmlHttp = CreateObject("Microsoft.XMLHTTP")
With objXmlHttp
    .Open "GET", strImageURL, False
    .Send
End With 

Set objStream = CreateObject("Adodb.Stream")
With objStream
    .Type = 1 '//binary
    .Open
    .Write objXmlHttp.responseBody 
    .SaveToFile strImageFile, 2 '//overwrite
End With

Set objImageFile = CreateObject("WIA.ImageFile")
objImageFile.LoadFile strImageFile                          ' load image
If objImageFile.Height < lngHeight Then lngHeight = 0
lngBottomCrop = objImageFile.Height - lngHeight

Set objImageProcess = CreateObject("WIA.ImageProcess") 
objImageProcess.Filters.Add objImageProcess.FilterInfos("Crop").filterid 'setup filter
With objImageProcess.Filters(1)
    .Properties("Left") = 0
    .Properties("Top") = 0
    .Properties("Right") = 0 
    .Properties("Bottom") = lngBottomCrop
End With

Set objImageFile = objImageProcess.Apply(objImageFile) 'apply change
objFSO.DeleteFile strImageFile ' delete original downloaded image
objImageFile.SaveFile strImageFile 'save cropped image version

' delete temp files created by cropping
On Error Resume Next 
objFSO.DeleteFile objShell.ExpandEnvironmentStrings("%TEMP%") & "\Img*.tmp", True 

Set objArgs = Nothing
Set objShell = Nothing
Set objFSO = Nothing
Set objXmlHttp = Nothing
Set objStream = Nothing

WScript.Quit
```
python python-2.7 libraries wia
1个回答
0
投票
import win32com.client
shell = win32com.client.Dispatch("WScript.Shell")
fo = win32com.client.Dispatch("Scripting.FileSystemObject")
m = win32com.client.Dispatch("Microsoft.XMLHTTP")

这样的事情,我无法继续测试,因为我不知道输入什么,或者对Wscript的东西不太了解...

© www.soinside.com 2019 - 2024. All rights reserved.