jazzband / sorl-thumbnail

Thumbnails for Django
https://sorl-thumbnail.readthedocs.io
BSD 3-Clause "New" or "Revised" License
1.74k stars 493 forks source link

Unknown color specifier: '\x004\x88..............." #489

Open rvteja92 opened 7 years ago

rvteja92 commented 7 years ago

I am using sorl-thumbnail 12.3 in django model like below.

from sorl.thumbnail import get_thumbnail

class InsuranceCompany(Model):
    logo = ImageField(upload_to='company_logo/%Y/%m/%d', null=True)

    @property
    def logo_cropped(self):
         if self.logo:
            return get_thumbnail(self.logo, "250x250", crop="center").url

While it works most of the times, sometimes it gives the following error for some images (and mostly for png images, or I felt so):

from PIL import ImageColor
-> 2031         color = ImageColor.getcolor(color, mode)
   2032 
   2033     return Image()._new(core.fill(mode, size, color))

/home/ubuntu/.virtualenvs/.../python2.7/site-packages/PIL/ImageColor.pyc in getcolor(color, mode)
    126     """
    127     # same as getrgb, but converts the result to the given mode
--> 128     color, alpha = getrgb(color), 255
    129     if len(color) == 4:
    130         color, alpha = color[0:3], color[3]

/home/ubuntu/.../python2.7/site-packages/PIL/ImageColor.pyc in getrgb(color)
    111             int(m.group(4))
    112             )
--> 113     raise ValueError("unknown color specifier: %r" % color)
    114 
    115 

ValueError: unknown color specifier: '\x004\x88\x86u\x84\xa1\xac\x8a\t\xcfr6\xf9c~t\x10\xd7p\x8ch-mf\x9d\xaa\xb2\xb7\xb0\xa2\x8f`;\r\x1ffl\x93\xa7\xaf\xb3\x8a;h\x02\x19\'8to\x9c\xae`&\x83\x98d\x12\x05\x10\x9b\xca\xf4\xfd\xce#\xb1\xe8\xd12\xbb\x819\xbf\xc5\xd1\xe2\xf1\x91\xc1\xee\xdc~w[\x86ld\xe0[^\xd2\x0c\xba\xb9h\xe8n\xf4t[=\xc0?k\xb0:\xfa{!\xeb\x92|4\xf7.\x9cgr\x17cuxko\xf5\x0c\xd8\x10\x1b\x07\x1d\xe3\xf1\xb5\xec\xb7*\xfd\xcb\xf0s\xd8\xb6\xc1\xe6\xdc\x1c\xe8\xad\xec\x1f\xe7\xe5\xfe\xeb\xe2).2\x05\x96\x17\xf9\x1c\x1a\xbdo\x14\xc5\xc6|\xc9t\xb4&\xd9\xf9"\xe4\xdc%\xdexh\n\xdfd\xdf\xd0\xc4\x1b"\xcb\x18\xdf\xce\x16t\n\xcd*ju\xa9dk\xab\x0e\xd2p\xa0\xd2~h\x9a\xb3\xb7r\xca@\xab\xa5\xba\xb8\xbb{\x15x|'

Is it a problem from my side. Or is it a bug with the program.

adamchengqnap commented 7 years ago

Yes we also experienced this issue where images uploaded successfully but when rendering it on template it show this unknown color specifier error.

rvteja92 commented 7 years ago

@adamchengqnap did you solve it somehow?? Please share if you did.

denti commented 7 years ago

@rvteja92 while waiting for fix, you can roll-back on sorl-thumbnail==12.3 version. It helped to me.