الميزات: إضافة أدوات جديدة لمعالجة ملفات PDF، تشمل التلخيص والترجمة واستخراج الجداول.
- تفعيل مكون SummarizePdf لإنشاء ملخصات PDF باستخدام الذكاء الاصطناعي. - تفعيل مكون TranslatePdf لترجمة محتوى PDF إلى لغات متعددة. - تفعيل مكون TableExtractor لاستخراج الجداول من ملفات PDF. - تحديث الصفحة الرئيسية والتوجيه ليشمل الأدوات الجديدة. - إضافة ترجمات للأدوات الجديدة باللغات الإنجليزية والعربية والفرنسية. - توسيع أنواع واجهة برمجة التطبيقات (API) لدعم الميزات الجديدة المتعلقة بمعالجة ملفات PDF. --feat: Initialize frontend with React, Vite, and Tailwind CSS - Set up main entry point for React application. - Create About, Home, NotFound, Privacy, and Terms pages with SEO support. - Implement API service for file uploads and task management. - Add global styles using Tailwind CSS. - Create utility functions for SEO and text processing. - Configure Vite for development and production builds. - Set up Nginx configuration for serving frontend and backend. - Add scripts for cleanup of expired files and sitemap generation. - Implement deployment script for production environment.
This commit is contained in:
74
backend/app/services/qrcode_service.py
Normal file
74
backend/app/services/qrcode_service.py
Normal file
@@ -0,0 +1,74 @@
|
||||
"""QR Code generation service."""
|
||||
import os
|
||||
import logging
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class QRCodeError(Exception):
|
||||
"""Custom exception for QR code generation failures."""
|
||||
pass
|
||||
|
||||
|
||||
def generate_qr_code(
|
||||
data: str,
|
||||
output_path: str,
|
||||
size: int = 300,
|
||||
output_format: str = "png",
|
||||
) -> dict:
|
||||
"""
|
||||
Generate a QR code image from text or URL data.
|
||||
|
||||
Args:
|
||||
data: The content to encode (URL, text, etc.)
|
||||
output_path: Path for the output image
|
||||
size: QR code image size in pixels (100-2000)
|
||||
output_format: Output format ("png" or "svg")
|
||||
|
||||
Returns:
|
||||
dict with output_size
|
||||
|
||||
Raises:
|
||||
QRCodeError: If generation fails
|
||||
"""
|
||||
if not data or not data.strip():
|
||||
raise QRCodeError("No data provided for QR code.")
|
||||
|
||||
if len(data) > 4000:
|
||||
raise QRCodeError("Data too long. Maximum 4000 characters.")
|
||||
|
||||
size = max(100, min(2000, size))
|
||||
os.makedirs(os.path.dirname(output_path), exist_ok=True)
|
||||
|
||||
try:
|
||||
import qrcode
|
||||
from PIL import Image
|
||||
|
||||
qr = qrcode.QRCode(
|
||||
version=None,
|
||||
error_correction=qrcode.constants.ERROR_CORRECT_M,
|
||||
box_size=10,
|
||||
border=4,
|
||||
)
|
||||
qr.add_data(data)
|
||||
qr.make(fit=True)
|
||||
|
||||
img = qr.make_image(fill_color="black", back_color="white")
|
||||
|
||||
# Resize to requested size
|
||||
img = img.resize((size, size), Image.Resampling.LANCZOS)
|
||||
img.save(output_path)
|
||||
|
||||
output_size = os.path.getsize(output_path)
|
||||
logger.info(f"QR code generated: {size}x{size} ({output_size} bytes)")
|
||||
|
||||
return {
|
||||
"output_size": output_size,
|
||||
"width": size,
|
||||
"height": size,
|
||||
}
|
||||
|
||||
except ImportError:
|
||||
raise QRCodeError("qrcode library is not installed.")
|
||||
except Exception as e:
|
||||
raise QRCodeError(f"Failed to generate QR code: {str(e)}")
|
||||
Reference in New Issue
Block a user