I got this following error while running the python program."AttributeError: module 'PIL.Image' has no attribute 'ANTIALIAS' in PYTHON".
The below python program is to download image from URL and save it to the pdf file.
CODE:
import requests from reportlab.lib.pagesizes import letter from reportlab.pdfgen import canvas from PIL import Image from io import BytesIO image_url = 'https://tensix.com/wp-content/uploads/2023/11/P6-EPPM-Baseline-Update-Fig-1.jpg' response = requests.get(image_url) if response.status_code == 200: img = Image.open(BytesIO(response.content)) pdf_file = "output.pdf" c = canvas.Canvas(pdf_file, pagesize=letter) max_width = 500 width_percent = max_width / float(img.size[0]) height = int(float(img.size[1]) * float(width_percent)) img = img.resize((max_width, height), Image.Resampling.LANCZOS) temp_img_path = 'temp_image.png' img.save(temp_img_path) c.drawImage(temp_img_path, 50, 700 - height) c.save() print(f"PDF generated with the image: {pdf_file}") else: print("Failed to fetch the image.")
SOLUTION:
ANTIALIAS is worked in old versions. If you are using Pillow 10.0.0 and above You need to use PIL.Image.LANCZOS or PIL.Image.Resampling.LANCZOS.
img = img.resize((max_width, height), Image.Resampling.LANCZOS)
VIDEO GUIDE:
Post your comments / questions
Recent Article
- The request was aborted: Could not create SSL/TLS secure channel -Error in Asp.net
- FieldError: Cannot resolve keyword 'id' into field in Django project
- How to hide the ID field from the Django admin?
- It is impossible to add a non nullable field without specifying a default. Django error
- ImportError: cannot import name 'url' from 'django.conf.urls' - Django Error
- How to Enable Virtualization in BIOS Security Settings in Intel Processors For Android Studio?
- Dependency 'androidx.activity:activity:1.8.0' requires libraries and applications that depend on it.
- AttributeError: 'NoneType' object has no attribute 'get_text' - Python
Related Article