title: generate thumbnail when image uploaded django
body: <p>i have a website where multiple large size images uploaded everyday after they go live because of heavy size its taking time so i want to generate thumbnail version when image uploaded:</p>
  
  <pre><code>class Image(models.Model):
        license_type = (
      ('Royalty-Free','Royalty-Free'),
      ('Rights-Managed','Rights-Managed')
                           )
        image_number = models.CharField(default=random_image_number,max_length=12,unique=True)
        title = models.CharField(default=random_image_number,max_length = 100)
        image = models.ImageField(upload_to = 'image' , default = 'demo/demo.png')
        thumbnail = models.ImageField(upload_to='thumbs', editable=False)
        category = models.ForeignKey('Category', null=True, blank=True, on_delete=models.CASCADE)
        shoot = models.ForeignKey(ImageShoot, on_delete=models.CASCADE, related_name='Image', null=True,blank=True)
        image_keyword = models.TextField(max_length=1000)
        credit = models.CharField(max_length=150, null=True)
        location = models.CharField(max_length=100, null=True)
        license_type = models.CharField(max_length=20,choices=license_type, default='')
        uploaded_at = models.TimeField(auto_now_add=True)
  
        def __str__(self):
            return self.title
  
        def save(self, *args, **kwargs):
  
            super(Image, self).save(*args, **kwargs)
            if not self.make_thumbnail():
               raise Exception('Could not create thumbnail - is the file type valid?')
  
        def make_thumbnail(self):
            fh = storage.open(self.Image.name)
            try:
               image = PILImage.open(fh)
            except:
               return False
            image.thumbnail((400,400),PILImage.ANTIALIAS)
            fh.close()
            thumb_name, thumb_extension = os.path.splitext(self.Image.name)
            thumb_extension = thumb_extension.lower()
  
            thumb_filename = thumb_name + '_thumb' + thumb_extension
  
            if thumb_extension in ['.jpg', '.jpeg']:
               FTYPE = 'JPEG'
            elif thumb_extension == '.gif':
                 FTYPE = 'GIF'
            elif thumb_extension == '.png':
                 FTYPE = 'PNG'
            else:
               return False    # Unrecognized file type
  
      # Save thumbnail to in-memory file as StringIO
           temp_thumb = StringIO()
           image.save(temp_thumb, FTYPE)
           temp_thumb.seek(0)
  
      # Load a ContentFile into the thumbnail field so it gets saved
           self.thumbnail.save(thumb_filename, ContentFile(temp_thumb.read()), save=True)
           temp_thumb.close()
  
           return True
  </code></pre>
  
  <p>admin.py:</p>
  
  <pre><code>@admin.register(Image)
  class ImageAdmin(admin.ModelAdmin):
        readonly_fields=['image_number','uploaded_at']
        fields = ['title','image_number','shoot','category',
           'image','image_keyword','credit','license_type','location','uploaded_at']
  </code></pre>
  
  <p>now this is the error:</p>
  
  <pre><code>string argument expected, got 'bytes'
  </code></pre>
  
  <p>backtrace:</p>
  
  <pre><code>File "/home/tboss/Desktop/environment/live/backend/venv/lib/python3.7/site-packages/PIL/JpegImagePlugin.py", line 779, in _save
  ImageFile._save(im, fp, [("jpeg", (0, 0) + im.size, 0, rawmode)], bufsize)
  File "/home/tboss/Desktop/environment/live/backend/venv/lib/python3.7/site-packages/PIL/ImageFile.py", line 513, in _save
  fp.write(d)
  TypeError: string argument expected, got 'bytes'
  </code></pre>
  
  <p>when i user BytesIO:</p>
  
  <p>i get this error:</p>
  
  <pre><code>maximum recursion depth exceeded in comparison
  </code></pre>
  
  <p>backtrace:</p>
  
  <pre><code> File "/home/tboss/Desktop/environment/live/backend/venv/lib/python3.7/site-packages/PIL/TiffImagePlugin.py", line 319, in __init__
    if isinstance(value, Fraction):
   File "/home/tboss/Desktop/environment/live/backend/venv/lib/python3.7/abc.py", line 139, in __instancecheck__
   return _abc_instancecheck(cls, instance)
  </code></pre>
  
  <p>RecursionError: maximum recursion depth exceeded in comparison</p>
  
  <p>i am current uploading image from admin but also going to using drf. currently its not creating thumbnail.............................................................................................................</p>