Pillow
Pillow copied to clipboard
Problems with image from iPhone 14
What did you do?
Im trying make a simple upload from iPhone 14 and save the image.
It works from my iPhone 13 but not for iPhone 14.
I try select different compatible mode, different size etc.
What did you expect to happen?
Normal upload.
What actually happened?
Bad headers errors:
DEBUG 2024-10-19 17:53:50,220 TiffImagePlugin tag: MPFVersion (45056) - type: undefined (7) - value: b'0100'
DEBUG 2024-10-19 17:53:50,220 TiffImagePlugin tag: NumberOfImages (45057) - type: long (4) - value: b'\x00\x00\x00\x02'
DEBUG 2024-10-19 17:53:50,221 TiffImagePlugin tag: MPEntry (45058) - type: undefined (7) Tag Location: 46 - Data Location: 50 - value: b'\x00\x03\x00\x00\x003]\xee\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x04\xe4\xa0\x003$S\x00\x00\x00\x00'
ERROR 2024-10-19 17:53:50,221 validators Failed to validate image: ['Tipo de imagem não suportado para o arquivo: IMG_5615.jpeg. Os tipos permitidos são: jpeg, png, webp.']
What are your OS, Python and Pillow versions?
- OS: linux
- Python: 10
- Pillow: 11
docker exec -it app-aixdg-1 python3 -m PIL.report
--------------------------------------------------------------------
Pillow 11.0.0
Python 3.10.15 (main, Oct 19 2024, 04:00:28) [GCC 12.2.0]
--------------------------------------------------------------------
Python executable is /usr/local/bin/python3
System Python files loaded from /usr/local
--------------------------------------------------------------------
Python Pillow modules loaded from /app/.local/lib/python3.10/site-packages/PIL
Binary Pillow modules loaded from /app/.local/lib/python3.10/site-packages/PIL
--------------------------------------------------------------------
--- PIL CORE support ok, compiled for 11.0.0
--- TKINTER support ok, loaded 8.6
--- FREETYPE2 support ok, loaded 2.13.2
--- LITTLECMS2 support ok, loaded 2.16
--- WEBP support ok, loaded 1.4.0
--- JPEG support ok, compiled for libjpeg-turbo 3.0.4
--- OPENJPEG (JPEG2000) support ok, loaded 2.5.2
--- ZLIB (PNG/ZIP) support ok, loaded 1.2.13
--- LIBTIFF support ok, loaded 4.6.0
--- RAQM (Bidirectional Text) support ok, loaded 0.10.1, fribidi 1.0.8, harfbuzz 10.0.1
*** LIBIMAGEQUANT (Quantization method) support not installed
--- XCB (X protocol) support ok
--------------------------------------------------------------------
import logging
from django.core.exceptions import ValidationError
from django.utils.translation import gettext_lazy as _
from PIL import Image
logger = logging.getLogger(__name__)
def validate_image_mimetype(value):
valid_mime_types = ["jpeg", "png", "webp"]
allowed_types = ", ".join(valid_mime_types)
file_name = value.name
# open the image and check its format
try:
image = Image.open(value)
mime_type = image.format.lower()
if mime_type not in valid_mime_types:
raise ValidationError(
_("error.unsupported-image-type %(file_name)s %(allowed_types)s"),
params={"file_name": file_name, "allowed_types": allowed_types},
)
except Exception as e:
logger.error(f"Failed to validate image: {e}")
raise ValidationError(
_("error.unsupported-image-type %(file_name)s %(allowed_types)s"),
params={"file_name": file_name, "allowed_types": allowed_types},
)
If anyone wanna test, it is here: https://aixdg.com/
Thanks.