我需要创建一个从URL提取图片并创建保存在本地计算机上的缩略图的函数。i不断出现语法错误并且无法弄清楚如何修复它 这是我到目前为止所能得到的,任何人都可以帮助我
import urllib
def main():
URL = "https://cdn.wallpapersafari.com/12/81/ptyhig.jpg"
DEST_FILE_NAME = "C:\Users\jen\OneDrive\Pictures"
urlib.urlretrieve (URL,DEST_FILE_NAME)
def resizeImage(srcPic,scale,dstWidth, dstHeight):
destPic = makeEmptyPicture (dstWidth, dstHeight)
#Adapted from https://cdn.wallpapersafari.com/12/81/ptyhig.jpg
#Copy selected pixels from original image to new scaled-down image
for x in range(dstHeight):
for y in range (dstHeight):
dst_pixel = getPixel(destPic, x , y)
src_pixel = getPixel(srcPic, int(x*scale), int(y*scale))
setColor(dst_pixel, getColor(src_pixel))
return destPic
def main():
srcFile + pickAFile()
srcPic + makePicture(srcFile)
srcWidth + getWidth(srcPic)
destWidth = 100
print "The width of the sourcefile is " + str(srcWidth)
if(srcWidth > dstWidth):
srcHeight = float(getHeight(srcPic)) # I am making this a float to help the ratio calculation
ratio = srcHeight/ float(srcWitdth)
scale = srcWidth / float(dstWidth)
print "Using scale " + str(scale) + " to reduce the picture"
print "The height:width ratio is " + str(ratio)
destHeight + int(ration'dstWidth + 0.5)
print "Adjusting to " + str(dstHeight) + " by " + str(dstWidth)
destPic = resizeImage(srcPic,scale,dstWidth,dstHeight)
destFileName = "C:\Users\jen\OneDrive\Pictures" + srcFile.split(\\")[-1]
print destFileName
writePictureTo(destPic, destFileName)
else:
print "It is already a thumbnail"
print "In your program you would copy the file to the thumb-file"