/**
|
* 图片处理工具包
|
*
|
* <h2>主要功能</h2>
|
* <ul>
|
* <li>智能图片压缩(专为OCR优化)</li>
|
* <li>高质量图片缩放</li>
|
* <li>图片格式转换</li>
|
* </ul>
|
*
|
* <h2>使用示例</h2>
|
*
|
* <h3>1. OCR图片智能压缩(推荐)</h3>
|
* <pre>
|
* // 自动压缩到3MB以下,保证OCR识别准确率
|
* File compressedFile = ImageCompressUtil.compressForOCR(multipartFile);
|
*
|
* // 自定义大小限制
|
* File compressedFile = ImageCompressUtil.compressForOCR(multipartFile, 5 * 1024 * 1024); // 5MB
|
* </pre>
|
*
|
* <h3>2. 按尺寸压缩</h3>
|
* <pre>
|
* // 压缩到指定宽高
|
* File compressedFile = ImageCompressUtil.compress(multipartFile, 1920, 1080, 0.85f);
|
* </pre>
|
*
|
* <h3>3. 按比例压缩</h3>
|
* <pre>
|
* // 缩小到原来的50%
|
* File compressedFile = ImageCompressUtil.compressByScale(multipartFile, 0.5, 0.90f);
|
* </pre>
|
*
|
* <h3>4. 高质量图片缩放</h3>
|
* <pre>
|
* BufferedImage originalImage = ImageIO.read(file);
|
* BufferedImage resizedImage = ImageCompressUtil.resizeImageHighQuality(originalImage, 800, 600);
|
* </pre>
|
*
|
* <h3>5. 自定义质量压缩</h3>
|
* <pre>
|
* BufferedImage image = ImageIO.read(file);
|
* File compressed = ImageCompressUtil.compressWithQuality(image, "photo.jpg", 0.80f); // 80%质量
|
* </pre>
|
*
|
* <h2>压缩质量常量</h2>
|
* <ul>
|
* <li>{@code ImageCompressUtil.HIGH_QUALITY} - 0.90(高质量,推荐OCR使用)</li>
|
* <li>{@code ImageCompressUtil.MEDIUM_QUALITY} - 0.80(中等质量)</li>
|
* <li>{@code ImageCompressUtil.LOW_QUALITY} - 0.75(低质量)</li>
|
* </ul>
|
*
|
* <h2>注意事项</h2>
|
* <ul>
|
* <li>压缩后的文件保存在系统临时目录,使用完毕后需手动删除</li>
|
* <li>OCR压缩会保证最小边不小于1500px,确保文字清晰</li>
|
* <li>支持PNG、BMP、GIF等格式自动转为JPEG</li>
|
* </ul>
|
*
|
* @author ruoyi
|
* @since 2025-01-20
|
*/
|
package com.ruoyi.common.utils.image;
|