Repository: CiviWiki/OpenCiviWiki

Issue:
When uploading a profile image failed then user needs to go back and click on Edit Profile again to upload new image
When users uploading a profile picture and this failed with the error message "Please use an image that 1280 x 960 pixels or smaller" then users need to go back to the profile and click on Edit Profile again in order to upload a new picture. Just clicking on Choose Picture doesn't do it.


Discussion:
@all-contributors please add @richifuentes for bug
@brylie 

I've put up [a pull request](https://github.com/CiviWiki/OpenCiviWiki/pull/471) to add @richifuentes! :tada:
Is this still an issue ? if soo can I be assigned on it ?
@wassafshahzad can you try to reproduce the issue? If you can't reproduce the issue, we can close the bug report as stale.
Sure I will try it 
Thank you

Resolving patch:
diff --git a/project/accounts/admin.py b/project/accounts/admin.py
--- a/project/accounts/admin.py
+++ b/project/accounts/admin.py
@@ -1,3 +1,6 @@
 from django.contrib import admin
+from .models import User
+
 
 # Register your models here.
+admin.site.register(User)
diff --git a/project/accounts/models.py b/project/accounts/models.py
--- a/project/accounts/models.py
+++ b/project/accounts/models.py
@@ -71,7 +71,8 @@ def card_summarize(self, profile, request_profile):
             "username": profile.user.username,
             "first_name": profile.first_name,
             "last_name": profile.last_name,
-            "about_me": profile.about_me[:about_me_truncate_length] + ellipsis_if_too_long,
+            "about_me": profile.about_me[:about_me_truncate_length]
+            + ellipsis_if_too_long,
             "profile_image": profile.profile_image_url,
             "follow_state": True
             if profile in request_profile.following.all()
@@ -155,7 +156,7 @@ def __init__(self, *args, **kwargs):
         super(Profile, self).__init__(*args, **kwargs)
 
     def save(self, *args, **kwargs):
-        """ Image crop/resize and thumbnail creation """
+        """Image crop/resize and thumbnail creation"""
 
         # New Profile image --
         if self.profile_image:
@@ -169,11 +170,7 @@ def resize_profile_image(self):
         """
         Resizes and crops the user uploaded image and creates a thumbnail version of it
         """
-        profile_image_field = self.profile_image
-        image_file = io.StringIO(profile_image_field.read())
-        profile_image = Image.open(image_file)
-        profile_image.load()
-
+        profile_image = Image.open(self.profile_image)
         # Resize image
         profile_image = ImageOps.fit(
             profile_image, PROFILE_IMG_SIZE, Image.ANTIALIAS, centering=(0.5, 0.5)
@@ -186,7 +183,7 @@ def resize_profile_image(self):
             profile_image = white_bg_img
 
         # Save new cropped image
-        tmp_image_file = io.StringIO()
+        tmp_image_file = io.BytesIO()
         profile_image.save(tmp_image_file, "JPEG", quality=90)
         tmp_image_file.seek(0)
         self.profile_image = InMemoryUploadedFile(
@@ -194,21 +191,23 @@ def resize_profile_image(self):
             "ImageField",
             self.profile_image.name,
             "image/jpeg",
-            tmp_image_file.len,
+            profile_image.tell(),
             None,
         )
         # Make a Thumbnail Image for the new resized image
         thumb_image = profile_image.copy()
+
         thumb_image.thumbnail(PROFILE_IMG_THUMB_SIZE, resample=Image.ANTIALIAS)
-        tmp_image_file = io.StringIO()
-        thumb_image.save(tmp_image_file, "JPEG", quality=90)
-        tmp_image_file.seek(0)
+        tmp_thumb_file = io.BytesIO()
+        thumb_image.save(tmp_thumb_file, "JPEG", quality=90)
+        tmp_thumb_file.seek(0)
+
         self.profile_image_thumb = InMemoryUploadedFile(
-            tmp_image_file,
+            tmp_thumb_file,
             "ImageField",
             self.profile_image.name,
             "image/jpeg",
-            tmp_image_file.len,
+            thumb_image.tell(),
             None,
         )
 


Test patch: