ImageUtils 生成缩略图,增加目标文件参数,可以不是原文件
This commit is contained in:
@@ -29,6 +29,13 @@ public class ImageUtils {
|
|||||||
* 缩略图生成,处理一些较大的图片,防止占用太多的网络资源
|
* 缩略图生成,处理一些较大的图片,防止占用太多的网络资源
|
||||||
*/
|
*/
|
||||||
public static void thumbnails(File imageFile, int maxWidth, int maxHeight, String outputFormat){
|
public static void thumbnails(File imageFile, int maxWidth, int maxHeight, String outputFormat){
|
||||||
|
thumbnails(imageFile, maxWidth, maxHeight, outputFormat, imageFile);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 缩略图生成,处理一些较大的图片,防止占用太多的网络资源
|
||||||
|
*/
|
||||||
|
public static void thumbnails(File imageFile, int maxWidth, int maxHeight, String outputFormat, File targetFile){
|
||||||
if (imageFile == null || !imageFile.exists() || (maxWidth <= 0 && maxHeight <= 0)){
|
if (imageFile == null || !imageFile.exists() || (maxWidth <= 0 && maxHeight <= 0)){
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -58,7 +65,7 @@ public class ImageUtils {
|
|||||||
if (StringUtils.isNotBlank(outputFormat)){
|
if (StringUtils.isNotBlank(outputFormat)){
|
||||||
bilder.outputFormat(outputFormat);
|
bilder.outputFormat(outputFormat);
|
||||||
}
|
}
|
||||||
bilder.toFile(imageFile);
|
bilder.toFile(targetFile);
|
||||||
}
|
}
|
||||||
}catch(IOException e){
|
}catch(IOException e){
|
||||||
logger.error("图片压缩失败:" + imageFile.getAbsoluteFile(), e);
|
logger.error("图片压缩失败:" + imageFile.getAbsoluteFile(), e);
|
||||||
|
|||||||
Reference in New Issue
Block a user