mirror of
https://github.com/Rushilwiz/pfp-frame.git
synced 2025-04-07 13:40:19 -04:00
feat: made image mod work
This commit is contained in:
parent
f3f93e85fc
commit
c5ce1d27c2
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -6,7 +6,7 @@ __pycache__/
|
||||||
local_settings.py
|
local_settings.py
|
||||||
db.sqlite3
|
db.sqlite3
|
||||||
db.sqlite3-journal
|
db.sqlite3-journal
|
||||||
media
|
|
||||||
|
|
||||||
# If your build process includes running collectstatic, then you probably don't need or want to include staticfiles/
|
# If your build process includes running collectstatic, then you probably don't need or want to include staticfiles/
|
||||||
# in your Git repository. Update and uncomment the following line accordingly.
|
# in your Git repository. Update and uncomment the following line accordingly.
|
||||||
|
|
|
@ -2,9 +2,11 @@ from django.db import models
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.contrib.auth.models import User
|
from django.contrib.auth.models import User
|
||||||
|
|
||||||
|
from django.core.files import File
|
||||||
from PIL import Image
|
from PIL import Image
|
||||||
import requests
|
import requests
|
||||||
from io import BytesIO
|
from io import BytesIO
|
||||||
|
from urllib.request import urlretrieve
|
||||||
|
|
||||||
|
|
||||||
# Create your models here.
|
# Create your models here.
|
||||||
|
@ -18,9 +20,9 @@ class Profile(models.Model):
|
||||||
|
|
||||||
def save(self, *args, **kwargs):
|
def save(self, *args, **kwargs):
|
||||||
super().save(*args, **kwargs)
|
super().save(*args, **kwargs)
|
||||||
r = requests.get(self.user.socialaccount_set.first().get_avatar_url())
|
if bool(self.image):
|
||||||
img = Image.open(BytesIO(r.content))
|
img = Image.open(self.image.path)
|
||||||
img.thumbnail((300,300))
|
frame = Image.open(settings.MEDIA_ROOT + "/frame.png")
|
||||||
print(img)
|
img.thumbnail((500, 500))
|
||||||
print(settings.MEDIA_ROOT + self.image.name)
|
img.paste(frame, (0,0), frame)
|
||||||
self.image.save("image.jpg", img)
|
img.save(self.image.path)
|
|
@ -3,6 +3,9 @@ from django.conf import settings
|
||||||
|
|
||||||
from .models import Profile
|
from .models import Profile
|
||||||
|
|
||||||
|
from urllib.request import urlretrieve
|
||||||
|
from django.core.files import File
|
||||||
|
|
||||||
# Create your views here.
|
# Create your views here.
|
||||||
|
|
||||||
def login(request):
|
def login(request):
|
||||||
|
@ -12,9 +15,7 @@ def redirect(request):
|
||||||
if not Profile.objects.filter(user=request.user).exists():
|
if not Profile.objects.filter(user=request.user).exists():
|
||||||
profile = Profile(user=request.user)
|
profile = Profile(user=request.user)
|
||||||
profile.save()
|
profile.save()
|
||||||
else:
|
req = urlretrieve(profile.user.socialaccount_set.first().get_avatar_url())
|
||||||
profile = Profile.objects.get(user=request.user)
|
profile.image.save("image.jpg", File(open(req[0], 'rb')))
|
||||||
profile.delete()
|
|
||||||
profile = Profile(user=request.user)
|
|
||||||
profile.save()
|
|
||||||
return render(request, 'frame/redirect.html', context={'data': profile})
|
return render(request, 'frame/redirect.html', context={'data': profile})
|
1
media/.gitignore
vendored
Normal file
1
media/.gitignore
vendored
Normal file
|
@ -0,0 +1 @@
|
||||||
|
profile_pics/*
|
BIN
media/frame.png
Normal file
BIN
media/frame.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 197 KiB |
Loading…
Reference in New Issue
Block a user