Skip to content

Error scaling BMP images in Plone 5.1.5 #34

@ewohnlich

Description

@ewohnlich

When calling a scale on a .bmp image I get this error.

Could not scale "<plone.namedfile.file.NamedBlobImage object at 0x7f3dbe51c758>" of <bound method Image.absolute_url of <Image at /Plone/cobweb.bmp>>
Traceback (most recent call last):
  File "/sprj/st_zope_plone5/buildouts/eggs/plone.namedfile-4.2.6-py2.7.egg/plone/namedfile/scaling.py", line 253, in __call__
    **parameters
  File "/sprj/st_zope_plone5/buildouts/eggs/plone.namedfile-4.2.6-py2.7.egg/plone/namedfile/scaling.py", line 200, in create_scale
    **parameters
  File "/sprj/st_zope_plone5/buildouts/eggs/plone.scale-3.0.3-py2.7.egg/plone/scale/scale.py", line 74, in scaleImage
    if all(rgb[0] == rgb[1] == rgb[2] for c, rgb in colors):
  File "/sprj/st_zope_plone5/buildouts/eggs/plone.scale-3.0.3-py2.7.egg/plone/scale/scale.py", line 74, in <genexpr>
    if all(rgb[0] == rgb[1] == rgb[2] for c, rgb in colors):
IndexError: tuple index out of range

I dug into this a bit in a debugger.

>>> img=app.unrestrictedTraverse('/Plone/cobweb.bmp')
>>> portrait=img.portrait
>>> from plone.scale.scale import scaleImage
>>> scaleImage(portrait.data, 16, 16)

This gives the same error as above. the value of image.format is "BMP" which will cause the scale to assume converting into JPEG. This triggers a later condition where it tries to check the RGB values for equality to determine if it's gray.

>>> import PIL.Image
>>> from StringIO import StringIO
>>> image = PIL.Image.open(StringIO(portrait.data))
>>> colors = image.getcolors(maxcolors=256)
>>> colors
[(59, (255, 255)), (8, (253, 255)), (4, (251, 255)), (4, (249, 255)), (3, (247, 255)), (2, (245, 255)), (1, (241, 255)), (3, (237, 255)), (1, (235, 255)), (2, (227, 255)), (2, (225, 255)), (2, (223, 255)), (3, (217, 255)), (2, (211, 255)), (2, (209, 255)), (1, (205, 255)), (1, (201, 255)), (1, (199, 255)), (1, (183, 255)), (1, (181, 255)), (1, (177, 255)), (1, (167, 255)), (1, (163, 255)), (2, (159, 255)), (1, (157, 255)), (1, (151, 255)), (1, (149, 255)), (2, (147, 255)), (1, (143, 255)), (1, (139, 255)), (1, (135, 255)), (2, (125, 255)), (1, (121, 255)), (2, (113, 255)), (1, (109, 255)), (1, (101, 255)), (1, (99, 255)), (1, (97, 255)), (1, (95, 255)), (2, (93, 255)), (3, (87, 255)), (1, (79, 255)), (1, (77, 255)), (3, (73, 255)), (1, (69, 255)), (1, (65, 255)), (2, (61, 255)), (2, (59, 255)), (1, (53, 255)), (1, (51, 255)), (1, (47, 255)), (2, (37, 255)), (1, (31, 255)), (1, (29, 255)), (10, (25, 255)), (2, (21, 255)), (1, (19, 255)), (2, (17, 255)), (3, (15, 255)), (1, (13, 255)), (2, (9, 255)), (1, (7, 255)), (1, (5, 255)), (1, (1, 255)), (2, (254, 255)), (5, (252, 255)), (2, (250, 255)), (2, (248, 255)), (1, (246, 255)), (5, (244, 255)), (2, (242, 255)), (1, (228, 255)), (1, (226, 255)), (2, (224, 255)), (1, (218, 255)), (1, (214, 255)), (2, (212, 255)), (2, (210, 255)), (1, (206, 255)), (1, (200, 255)), (2, (196, 255)), (1, (194, 255)), (1, (188, 255)), (1, (186, 255)), (1, (168, 255)), (1, (164, 255)), (1, (138, 255)), (1, (136, 255)), (1, (134, 255)), (1, (132, 255)), (1, (130, 255)), (1, (128, 255)), (1, (124, 255)), (1, (122, 255)), (2, (118, 255)), (1, (110, 255)), (1, (108, 255)), (1, (106, 255)), (1, (94, 255)), (1, (88, 255)), (1, (86, 255)), (2, (84, 255)), (1, (78, 255)), (1, (72, 255)), (1, (70, 255)), (1, (56, 255)), (1, (54, 255)), (2, (50, 255)), (1, (38, 255)), (1, (30, 255)), (3, (28, 255)), (1, (26, 255)), (1, (24, 255)), (2, (22, 255)), (1, (18, 255)), (1, (16, 255)), (2, (6, 255)), (1, (2, 255)), (6, (0, 255))]

As you can see the rgb values only have two values so rgb[2] throws an IndexError

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions