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

Я пытаюсь, чтобы JES jython создал функцию, которая извлекает изображение из URL, а затем сохраняет его в виде эскиза на локальном компьютере.

import urllib
url="https://upload.wikimedia.org/wikipedia/commons/thumb/0/0a/Python.svg/768px-Python.svg.png"
src = "D:\Users\Rudy\Desktop\W3_Thumbnail\thumbnail.png"

connect = urllib.urlretrieve(url,src)
#JES returns : I tried to read a file, and couldn't. Are you sure that file exists? If it does exist, did you specify the correct directory/
#folder? Please check line 6 of  #D:/Users/Rudy/Desktop\W3_Rudy_AccessingTheInternet.py
def scalePicture(src): 
    newWidth = getWidth(src)/2
    newHeight = getHeight(src)/2
    canvas = makeEmptyPicture(newWidth, newHeight)
    for x in range(newWidth):
        for y in range(newHeight):
            setColor(getPixel(canvas, x,y), getColor(getPixel(src, x*2, y*2)))
    return canvas

def thumbNail():
    srcPic = makePicture(src) 
    destWidth = getWidth(srcPic) / 2
    destHeight = getHeight(srcPic) / 2
    destPic = makeEmptyPicture(destWidth, destHeight)

    destPic = scalePicture(srcPic)
    show(srcPic)
    show(destPic)

thumbNail()
...