Skip to content

Instantly share code, notes, and snippets.

@rturowicz
Last active December 16, 2015 17:41
Show Gist options
  • Select an option

  • Save rturowicz/5472429 to your computer and use it in GitHub Desktop.

Select an option

Save rturowicz/5472429 to your computer and use it in GitHub Desktop.

Revisions

  1. rturowicz renamed this gist Apr 27, 2013. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  2. rturowicz created this gist Apr 27, 2013.
    19 changes: 19 additions & 0 deletions Asset.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,19 @@
    # models.py: overwritten model save method
    def save(self, *args, **kwargs):
    if self.cover:
    img_string = StringIO()
    pil_image = Image.open(self.cover.file)
    if pil_image:
    res_image = pil_image.resize((1034, 1400))
    res_image.save(img_string, pil_image.format)
    # original image replaced by thumbnail
    self.cover.file = InMemoryUploadedFile(
    img_string,
    self.cover.file.field_name,
    self.cover.file.name,
    self.cover.file.content_type,
    img_string.len,
    self.cover.file.charset
    )

    super(Issue, self).save()