Создайте функцию, которая извлекает изображение из URL и создает миниатюру, сохраненную на вашем локальном компьютере. - PullRequest
0 голосов
/ 15 апреля 2019

Мне нужно создать функцию, которая извлекает изображение из URL и создает миниатюру, сохраненную на вашем локальном компьютере. Я получаю синтаксическую ошибку и не могу понять, как ее исправить. Это то, что я получил, может кто-нибудь, пожалуйста, помогитеменя вышли

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"
...