Python Instabot错误-照片没有兼容的照片纵横比
我正在制作Instagram自动化程序。但我上传照片时出错了。是否有任何程序可以根据兼容的纵横比调整图像大小 这是我的节目:Python Instabot错误-照片没有兼容的照片纵横比,python,python-3.x,python-imaging-library,Python,Python 3.x,Python Imaging Library,我正在制作Instagram自动化程序。但我上传照片时出错了。是否有任何程序可以根据兼容的纵横比调整图像大小 这是我的节目: from instabot import Bot import os import random from PIL import Image import smtplib cwd = os.getcwd() bot = Bot() bot.login(username="myusername", password="*********&
from instabot import Bot
import os
import random
from PIL import Image
import smtplib
cwd = os.getcwd()
bot = Bot()
bot.login(username="myusername", password="*********")
files_name = os.listdir(f"{cwd}/photos")
def send_email():
email = "myemail@hostname.com"
password = "*****************"
s = smtplib.SMTP('smtp.gmail.com', 587)
s.starttls()
s.login(email, password)
s.sendmail(email, email, f"Available Photos in Storage {len(files_name)}")
s.quit()
file = random.choice(files_name)
split_file_name = str(file).split(".")
ext = str(split_file_name[1])
if ext == 'png':
img = Image.open(f"{cwd}/photos/{file}")
jpeg_img = img.convert('RGB')
jpeg_img.save(f"{cwd}/photos/converted.jpeg")
bot.upload_photo(f"{cwd}/photos/converted.jpeg", "caption")
os.remove(f"{cwd}/photos/{file}.REMOVE_ME")
os.remove(f"{cwd}/photos/converted.jpeg.REMOVE_ME")
else:
bot.upload_photo(f"{cwd}/photos/{file}", "caption")
os.remove(f"{cwd}/photos/{file}.REMOVE_ME")
if len(files_name) <= 10:
send_email()
请共享任何与instagram不兼容的调整图像大小的程序。
提前感谢。这里是最常见的Instagram照片和视频尺寸的快速列表:
Type of Instagram Post Aspect Ratio Instagram Post Size
Square Photo 1:1 1080 x 1080px
Landscape Photo 1.91:1 1080 x 608px
Portrait Photo 4:5 1080 x 1350px
Instagram Stories 9:16 1080 x 1920px
IGTV Cover Photo 1:1.55 420 x 654px
Instagram Square Video 1:1 1080 x 1080px
Instagram Landscape Video 1.91:1 1080 x 608px
Instagram Portrait Video 4:5 1080 x 1350px
可以使用Python图像库调整图像大小
from PIL import Image
im = Image.open("bear.jpg")
newsize = (1080, 1080)
im1 = im1.resize(newsize)
im.save('resized_bear_photo.jpg')
以下是最常见的Instagram照片和视频尺寸的快速列表:
Type of Instagram Post Aspect Ratio Instagram Post Size
Square Photo 1:1 1080 x 1080px
Landscape Photo 1.91:1 1080 x 608px
Portrait Photo 4:5 1080 x 1350px
Instagram Stories 9:16 1080 x 1920px
IGTV Cover Photo 1:1.55 420 x 654px
Instagram Square Video 1:1 1080 x 1080px
Instagram Landscape Video 1.91:1 1080 x 608px
Instagram Portrait Video 4:5 1080 x 1350px
可以使用Python图像库调整图像大小
from PIL import Image
im = Image.open("bear.jpg")
newsize = (1080, 1080)
im1 = im1.resize(newsize)
im.save('resized_bear_photo.jpg')