Python을 사용하여 Instagram과 호환되는 이미지 만들기
Instagram 친화적인 이미지란 무엇을 의미합니까?
인스타그램은 기본적으로 모든 종류의 이미지( )를 지원하지만 사각형 모양의 사진이 가장 잘 어울립니다.
따라서 사진을 1080 x 1080 픽셀 크기로 조정해야 합니다.

다음과 같이 여러 사용 사례가 가능합니다.





따라서 여기서 아이디어는 원본 이미지의 최대 공간만 사용하고 남은 영역이 있는 경우 색상으로 채우는 것입니다.

Pillow(Python의 이미지 조작 라이브러리)를 사용하여 이미지를 처리합니다. 설치하지 않은 경우 아래 명령 사용
pip install Pillow
from PIL import Image
import requests
def make_square(im, min_size=1080, fill_color=(0, 0, 0, 0)):
x, y = im.size
print("Original size "+str(x)+" X "+str(y))
size = max(min_size, x, y)
new_im = Image.new('RGB', (size, size), fill_color)
if(x > y):
mod = size/x
x = int(x * mod)
y = int(y * mod)
elif(x < y):
mod = size/y
x = int(x * mod)
y = int(y * mod)
new_im.paste(im.resize((x,y)), (int((size - x) / 2), int((size - y) / 2)))
x, y = new_im.size
print("New size "+str(x)+" X "+str(y))
return new_im
def processImage(url):
img = Image.open(requests.get(url, stream=True).raw)
new_img = make_square(img)
new_img.show()
processImage("https://images.pexels.com/photos/771742/pexels-photo-771742.jpeg?auto=compress&cs=tinysrgb&w=1260&h=750&dpr=1")
원본 이미지:

크기 조정된 이미지:

제곱 이미지를 반환합니다.
행복한 코딩 <3
Reference
이 문제에 관하여(Python을 사용하여 Instagram과 호환되는 이미지 만들기), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://dev.to/ashusharmatech/make-image-instagram-compatible-using-python-16bo텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)