【问题标题】:Aspect ration of a image for instagramInstagram 图像的纵横比
【发布时间】:2019-10-21 10:59:46
【问题描述】:

我想用 python 更改 Instagram 图像的纵横比。这是我更改纵横比的代码:

width,height=imageFile.size
aspectRatio = width/height
if(aspectRatio>=0.80 and aspectRatio<=1.90):
    print("yeah")
else:
    if(height>width):
        futureHeight =  width/.85
        print(str(width)+" ,"+str(futureHeight))
        print(width/futureHeight)
        left = 0
        int(futureHeight)
        teetet = height-futureHeight/2
        top = teetet / 4
        right = width
        bottom = height -150
    im1 = imageFile.crop((left, top, right, bottom)) 
    print(im1.size)
    im1.show() 
    im1.save(image)

但它仍然显示 ValueError: 宽高比不兼容。

每当我尝试上传这张图片时

【问题讨论】:

标签: python-3.x image-processing python-imaging-library instagram instagram-api


【解决方案1】:

我使用基本尺寸解决了这个问题。使用检查器,我看到 instagram 在主页中将图像转换为 598.02x598.02,所以我输入:

im=PIL.Image.open(path)
im=im.resize((598,598), Image.ANTIALIAS)
im.save(path) # overwrite the image

而不是

im=PIL.Image.open(path)
baseheight = 560
hpercent = (baseheight / float(im.size[1]))
wsize = int((float(im.size[0]) * float(hpercent)))
im=im.resize((wsize, baseheight), PIL.Image.ANTIALIAS)
im.save(path)

无论如何,纵横比超出范围。

现在您可以使用 instabot 之类的工具轻松发布它,因为纵横比为 1.0。

【讨论】:

    猜你喜欢
    • 2018-10-25
    • 2019-04-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-04-03
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多