def save(self, force_insert=False, force_update=False, *args, **kwargs):
        if not self.id:
            response = urllib.urlopen(self.external_image.url)
            data = StringIO(response.read())
            im = Image.open(data)

            size = im.size
            ratio = size[1] / size[0]

            if self.width >= size[0]:
                resized = im
            else:
                try:
                    resized = im.resize((self.width, int(round(self.width*ratio))), Image.ANTIALIAS)
                except IOError, e:
                    if e.message == "cannot read interlaced PNG files":
                        # Ain't nothing can be done until you upgrade PIL to 1.1.7
                        resized = im
                    else:
                        raise
            self.width, self.height = resized.size

            try:
                resized.save(self.get_filename(), format='jpeg')
                self.content_type = 'image/jpeg'
            except IOError, e:
                try:
                    resized.convert('RGB').save(self.get_filename(), format='jpeg')
                    self.content_type = 'image/jpeg'
                except __HOLE__:
                    open(self.get_filename(), 'wb').write(data.getvalue())
                    self.content_type = response.headers['content-type']

            self.external_image.width = size[0]
            self.external_image.height = size[1]

        super(ExternalImageSized, self).save(force_insert=False, force_update=False, **kwargs)
dataset/ETHPy150Open mollyproject/mollyproject/molly/external_media/models.py/ExternalImageSized.save