| 123456789101112131415161718192021 |
- import base64
- from io import BytesIO
- from PIL import Image
- import requests
- def image_to_base(image_path):
- with open(image_path, 'rb') as image_file:
- image_base = base64.b64encode(image_file.read()).decode('utf-8')
- return image_base
- def load_image_from_url(image_url):
- """根据url加载图像"""
- headers = {
- "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/110.0.0.0 Safari/537.36",
- "Referer": "https://www.aliexpress.com/",
- "Accept-Language": "en-US,en;q=0.9",
- }
- response = requests.get(image_url, headers=headers)
- image = Image.open(BytesIO(response.content))
-
- return image
|