0

I need to display the png transparent image in the frontend but am unable to format it correctly.

i have tried to change the format to png but it is rendering a black background to it.

class HelpCategories(models.Model):
    Name1 = (
        ('Getting Started','Getting Started'),
        ('Pricing','Pricing'),
        ('Integration','Integration'),
        ('Security','Security'),
        ('Product Professionals','Product Professionals'),
        ('About Products','About Products'),
    )
    Title = models.CharField(max_length=40, default='Getting Started')
    image = ImageField(upload_to='help_image', null=True, blank=True)

    def __str__(self):
        return self.Title

    def save(self, *args, **kwargs):
        if self.image:
            imageTemporary = Image.open(self.image).convert('RGB')
            outputIoStream = BytesIO()
            imageTemporaryResized = imageTemporary.resize((400,400)) 
            imageTemporaryResized.save(outputIoStream, format='PNG', quality=300)
            outputIoStream.seek(0)
            self.image = InMemoryUploadedFile(outputIoStream,'ImageField', "%s.png" % self.image.name.split('.')[0], 'image/png', sys.getsizeof(outputIoStream), None)
            super(HelpCategories, self).save(*args, **kwargs)

I need to be able to see only the image object in the template.

gachdavit
  • 1,223
  • 1
  • 6
  • 7

0 Answers0