Add Docker support and improve PDF conversion
Features: - Dockerfile for containerized deployment - Docker Compose configuration with health checks - Automated database initialization via entrypoint script - Quick start script for easy Docker deployment - Comprehensive Docker deployment documentation (DOCKER.md) - Complete README with installation and usage instructions - .dockerignore for optimized image builds Improvements: - PDF conversion now preserves orientation (portrait/landscape) - PDF rendering at 300 DPI for sharp quality - Maintains aspect ratio during conversion - Compact media library view with image thumbnails - Better media preview with scrollable gallery Docker Features: - Multi-stage build for smaller images - Non-root user for security - Health checks for container monitoring - Volume mounts for persistent data - Production-ready Gunicorn configuration - Support for Redis caching (optional)
This commit is contained in:
@@ -308,12 +308,11 @@ def process_pdf_file(filepath: str, filename: str) -> tuple[bool, str]:
|
||||
|
||||
log_action('info', f'Converting PDF to images: {filename}')
|
||||
|
||||
# Convert PDF pages to images at Full HD resolution
|
||||
# Convert PDF pages to images at high DPI for quality
|
||||
images = convert_from_path(
|
||||
filepath,
|
||||
dpi=150, # Good quality for Full HD display
|
||||
fmt='png',
|
||||
size=(1920, 1080) # Direct Full HD output
|
||||
dpi=300, # 300 DPI for sharp rendering
|
||||
fmt='png'
|
||||
)
|
||||
|
||||
if not images:
|
||||
@@ -323,18 +322,34 @@ def process_pdf_file(filepath: str, filename: str) -> tuple[bool, str]:
|
||||
base_filename = Path(filename).stem
|
||||
upload_folder = os.path.dirname(filepath)
|
||||
|
||||
# Save each page directly as PNG
|
||||
# Save each page with proper aspect ratio preservation
|
||||
converted_files = []
|
||||
for idx, image in enumerate(images, start=1):
|
||||
# Create filename for this page
|
||||
page_filename = f"{base_filename}_page{idx:03d}.png"
|
||||
page_filepath = os.path.join(upload_folder, page_filename)
|
||||
|
||||
# Save the image directly without additional optimization
|
||||
image.save(page_filepath, 'PNG', optimize=True)
|
||||
# Determine orientation and resize maintaining aspect ratio
|
||||
width, height = image.size
|
||||
is_portrait = height > width
|
||||
|
||||
# Define Full HD dimensions based on orientation
|
||||
if is_portrait:
|
||||
# Portrait: max height 1920, max width 1080 (rotated Full HD)
|
||||
max_size = (1080, 1920)
|
||||
else:
|
||||
# Landscape: max width 1920, max height 1080 (standard Full HD)
|
||||
max_size = (1920, 1080)
|
||||
|
||||
# Resize maintaining aspect ratio (thumbnail maintains ratio)
|
||||
from PIL import Image as PILImage
|
||||
image.thumbnail(max_size, PILImage.Resampling.LANCZOS)
|
||||
|
||||
# Save the optimized image
|
||||
image.save(page_filepath, 'PNG', optimize=True, quality=95)
|
||||
|
||||
converted_files.append((page_filepath, page_filename))
|
||||
log_action('info', f'Converted PDF page {idx}/{len(images)}: {page_filename}')
|
||||
log_action('info', f'Converted PDF page {idx}/{len(images)} ({width}x{height} -> {image.size[0]}x{image.size[1]}): {page_filename}')
|
||||
|
||||
log_action('info', f'PDF converted successfully: {len(images)} pages from {filename}')
|
||||
|
||||
|
||||
Reference in New Issue
Block a user