支持JPEG照片并保留原始尺寸

This commit is contained in:
2026-11-19 14:45:26 +08:00
parent 7520949b3b
commit 08f18b784f
5 changed files with 25 additions and 10 deletions
+14
View File
@@ -1,6 +1,7 @@
import asyncio
import io
import tempfile
from PIL import Image
from pathlib import Path
from unittest.mock import patch
from sqlalchemy import insert, select
@@ -27,6 +28,19 @@ class DirectCenterPhotoTests(ApiTestCase):
self.assertEqual(result.status_code,200,result.text);ids.append(result.json()['id'])
return ids
async def test_jpeg_variants_convert_to_unified_original_size_jpeg(self):
owner=await register(self.client,'jpegvariants');headers=auth(owner['token'])
image=Image.new('RGB',(4021,237),'white')
raw=io.BytesIO();image.save(raw,'JPEG')
result=await self.client.post('/api/center/photos',headers=headers,content=raw.getvalue())
self.assertEqual(result.status_code,200,result.text)
photo=await self.client.get('/api/center/photos/'+result.json()['id'],headers=headers)
self.assertEqual(photo.status_code,200)
self.assertEqual(photo.headers['content-type'],'image/jpeg')
with Image.open(io.BytesIO(photo.content)) as stored:
self.assertEqual(stored.format,'JPEG')
self.assertEqual(stored.size,(4021,237))
async def test_photo_only_creation_supplement_and_edit_preserve_all_members_photos(self):
owner=await register(self.client,'directowner');member=await register(self.client,'directmember')
c=self.client;oh=auth(owner['token']);mh=auth(member['token'])