File size: 833 Bytes
877e000
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# models/image_quality.py

from PIL import Image
from .logging_config import logger

def assess_image_quality(img):
    try:
        if img is None:
            logger.error("No image provided to assess_image_quality.")
            return {
                'resolution': 'unknown',
                'quality_score': 0,
                'error': 'No image provided'
            }
        width, height = img.size
        resolution = width * height
        quality_score = min(100, resolution // 20000)
        return {
            'resolution': f"{width}x{height}",
            'quality_score': quality_score
        }
    except Exception as e:
        logger.error(f"Error assessing image quality: {str(e)}")
        return {
            'resolution': 'unknown',
            'quality_score': 0,
            'error': str(e)
        }