1

I'm trying to save a jSignature image to a django FileField. My form save code, as it stands, is as follows:

def save(self, commit=True):
    instance = super(ApplicationForRetailInstallmentContractForm, self).save(commit=False)
    signature = self.cleaned_data.get('signature')
    signature_image = draw_signature(signature)
    # at this point, signature_image is a PIL.Image.Image instance
    signature_image.show()
    signature_io = StringIO.StringIO()
    signature_image.save(signature_io, format='JPEG')
    thumb_file = InMemoryUploadedFile(
        signature_io,
        None,
        '%s signature.jpg' % instance.name,
        'image/jpeg',
        signature_io.len,
        None,
    )
    instance.signature = thumb_file
    if commit:
        instance.save()
    return instance

Currently, when the signature is saved to the filefield, it creates an image with the correct resolution, but that is completely black, which obviously is incorrect. Because we use google buckets for the live version of the site's media, a solution that involves creating actual local files won't work. Ultimately, I have two questions:

  1. What could be causing the image to save incorrectly? 2. Is it possible to use something like signature_image.show() (which currently shows no errors but also displays nothing) from within django to view the image as it exists in PIL.Image.Image form, so that I can figure out where in the process the image is getting corrupted? I was able to get the image to display by installing imagemagick as recommended in Image.show() won't display the picture, and since the image is black all the way up in the call to show(), i believe it's not a problem with any of the posted code.
Community
  • 1
  • 1
Swagner
  • 53
  • 8

0 Answers0