DPI Upscaler & Checker
Check if images meet 300 DPI printing standards, and intelligently restore blurry low-resolution images using AI super-resolution technology.
Features
- - DPI Detection: Read and verify image DPI information
- Intelligent Analysis: Calculate actual print size and pixel density
- Super-Resolution Restoration: Use Real-ESRGAN algorithm to enhance image clarity
- Batch Processing: Support single image and batch folder processing
- Format Support: JPG, PNG, TIFF, BMP, WebP
Use Cases
- - Academic paper figure DPI checking
- Print image quality pre-inspection
- Low-resolution material restoration
- Document scan enhancement
Usage
Check Single Image DPI
CODEBLOCK0
Batch Check Folder
CODEBLOCK1
Super-Resolution Restoration
CODEBLOCK2
Batch Fix Low DPI Images
CODEBLOCK3
Parameters
Check Command
| Parameter | Type | Default | Required | Description |
|---|
| INLINECODE0 | string | - | Yes | Input image path or folder |
| INLINECODE1 |
string | stdout | No | Output report path |
|
--target-dpi | int | 300 | No | Target DPI threshold |
Upscale Command
| Parameter | Type | Default | Required | Description |
|---|
| INLINECODE3 | string | - | Yes | Input image path or folder |
| INLINECODE4 |
string | - | Yes | Output path |
|
--scale | int | 2 | No | Scale factor (2/3/4) |
|
--min-dpi | int | - | No | Only process images below this DPI |
|
--denoise | int | 0 | No | Denoise level (0-3) |
|
--face-enhance | flag | false | No | Enable face enhancement |
Output Description
DPI Check Report
CODEBLOCK4
Restored Image
- - Automatically saved as INLINECODE9
- Preserves original EXIF information
- Sets DPI to 300
Dependencies
- - Python >= 3.8
- Pillow >= 9.0.0
- opencv-python >= 4.5.0
- numpy >= 1.21.0
- realesrgan (optional, for best results)
Algorithm Description
DPI Calculation
CODEBLOCK5
Super-Resolution
- - Default use of Real-ESRGAN model
- Support lightweight bicubic interpolation fallback
- Intelligent model selection (general/anime/face)
Notes
- 1. Input image DPI information may be inaccurate; actual pixel calculation shall prevail
- Super-resolution cannot create non-existent information; extremely blurry images have limited improvement
- Large file processing requires more memory
- GPU acceleration requires CUDA environment (optional)
Risk Assessment
| Risk Indicator | Assessment | Level |
|---|
| Code Execution | Python/R scripts executed locally | Medium |
| Network Access |
No external API calls | Low |
| File System Access | Read input files, write output files | Medium |
| Instruction Tampering | Standard prompt guidelines | Low |
| Data Exposure | Output files saved to workspace | Low |
Security Checklist
- - [ ] No hardcoded credentials or API keys
- [ ] No unauthorized file system access (../)
- [ ] Output does not expose sensitive information
- [ ] Prompt injection protections in place
- [ ] Input file paths validated (no ../ traversal)
- [ ] Output directory restricted to workspace
- [ ] Script execution in sandboxed environment
- [ ] Error messages sanitized (no stack traces exposed)
- [ ] Dependencies audited
Prerequisites
CODEBLOCK6
Evaluation Criteria
Success Metrics
- - [ ] Successfully executes main functionality
- [ ] Output meets quality standards
- [ ] Handles edge cases gracefully
- [ ] Performance is acceptable
Test Cases
- 1. Basic Functionality: Standard input → Expected output
- Edge Case: Invalid input → Graceful error handling
- Performance: Large dataset → Acceptable processing time
Lifecycle Status
- - Current Stage: Draft
- Next Review Date: 2026-03-06
- Known Issues: None
- Planned Improvements:
- Performance optimization
- Additional feature support
DPI 缩放器与检查器
检查图像是否满足300 DPI打印标准,并使用AI超分辨率技术智能修复模糊的低分辨率图像。
功能特性
- - DPI检测:读取并验证图像DPI信息
- 智能分析:计算实际打印尺寸和像素密度
- 超分辨率修复:使用Real-ESRGAN算法增强图像清晰度
- 批量处理:支持单张图像和文件夹批量处理
- 格式支持:JPG、PNG、TIFF、BMP、WebP
应用场景
- - 学术论文图片DPI检查
- 打印图像质量预检
- 低分辨率素材修复
- 文档扫描件增强
使用方法
检查单张图像DPI
bash
python scripts/main.py check --input image.jpg
批量检查文件夹
bash
python scripts/main.py check --input ./images/ --output report.json
超分辨率修复
bash
python scripts/main.py upscale --input image.jpg --output upscaled.jpg --scale 4
批量修复低DPI图像
bash
python scripts/main.py upscale --input ./images/ --output ./output/ --min-dpi 300 --scale 2
参数说明
检查命令
| 参数 | 类型 | 默认值 | 必填 | 说明 |
|---|
| --input | 字符串 | - | 是 | 输入图像路径或文件夹 |
| --output |
字符串 | 标准输出 | 否 | 输出报告路径 |
| --target-dpi | 整数 | 300 | 否 | 目标DPI阈值 |
放大命令
| 参数 | 类型 | 默认值 | 必填 | 说明 |
|---|
| --input | 字符串 | - | 是 | 输入图像路径或文件夹 |
| --output |
字符串 | - | 是 | 输出路径 |
| --scale | 整数 | 2 | 否 | 缩放倍数(2/3/4) |
| --min-dpi | 整数 | - | 否 | 仅处理低于此DPI的图像 |
| --denoise | 整数 | 0 | 否 | 降噪等级(0-3) |
| --face-enhance | 标志 | false | 否 | 启用面部增强 |
输出说明
DPI检查报告
json
{
file: image.jpg,
dpi: [72, 72],
width_px: 1920,
height_px: 1080,
print
widthcm: 67.7,
print
heightcm: 38.1,
meets_300dpi: false,
recommended_scale: 4.17
}
修复后的图像
- - 自动保存为 <原始文件名>_upscaled.<扩展名>
- 保留原始EXIF信息
- 设置DPI为300
依赖项
- - Python >= 3.8
- Pillow >= 9.0.0
- opencv-python >= 4.5.0
- numpy >= 1.21.0
- realesrgan(可选,用于最佳效果)
算法说明
DPI计算
实际DPI = 像素尺寸 / 物理尺寸
打印尺寸(厘米)= 像素数 / DPI * 2.54
超分辨率
- - 默认使用Real-ESRGAN模型
- 支持轻量级双三次插值回退
- 智能模型选择(通用/动漫/人脸)
注意事项
- 1. 输入图像的DPI信息可能不准确,以实际像素计算为准
- 超分辨率无法创造不存在的信息,极度模糊的图像改善有限
- 处理大文件需要更多内存
- GPU加速需要CUDA环境(可选)
风险评估
| 风险指标 | 评估 | 等级 |
|---|
| 代码执行 | 本地执行Python/R脚本 | 中等 |
| 网络访问 |
无外部API调用 | 低 |
| 文件系统访问 | 读取输入文件,写入输出文件 | 中等 |
| 指令篡改 | 标准提示指南 | 低 |
| 数据泄露 | 输出文件保存到工作区 | 低 |
安全检查清单
- - [ ] 无硬编码的凭据或API密钥
- [ ] 无未经授权的文件系统访问(../)
- [ ] 输出不暴露敏感信息
- [ ] 已实施提示注入防护
- [ ] 输入文件路径已验证(无../遍历)
- [ ] 输出目录限制在工作区内
- [ ] 脚本在沙盒环境中执行
- [ ] 错误消息已清理(不暴露堆栈跟踪)
- [ ] 依赖项已审计
前置条件
bash
Python依赖项
pip install -r requirements.txt
评估标准
成功指标
- - [ ] 成功执行主要功能
- [ ] 输出符合质量标准
- [ ] 优雅处理边缘情况
- [ ] 性能可接受
测试用例
- 1. 基本功能:标准输入 → 预期输出
- 边缘情况:无效输入 → 优雅的错误处理
- 性能:大数据集 → 可接受的处理时间
生命周期状态
- - 当前阶段:草稿
- 下次审核日期:2026-03-06
- 已知问题:无
- 计划改进:
- 性能优化
- 额外功能支持