public
static
String generateThumbnail(ImageHolder thumbnail, String targetAddr) {
String realFileName = getRandomFileName();
String extension = getFileExtension(thumbnail.getImageName());
makeDirPath(targetAddr);
String relativeAddr = targetAddr + realFileName + extension;
logger.debug(
"current relativeAddr is :"
+ relativeAddr);
File dest =
new
File(PathUtil.getImgBasePath() + relativeAddr);
logger.debug(
"current complete addr is :"
+ PathUtil.getImgBasePath() + relativeAddr);
logger.debug(
"basePath is :"
+ basePath);
try
{
Thumbnails.of(thumbnail.getImage()).size(
200
,
200
)
.watermark(Positions.BOTTOM_RIGHT, ImageIO.read(
new
File(basePath +
"/watermark.jpg"
)),
0
.25f)
.outputQuality(
0
.8f).toFile(dest);
}
catch
(IOException e) {
logger.error(e.toString());
throw
new
RuntimeException(
"创建缩略图失败:"
+ e.toString());
}
return
relativeAddr;
}