if (errMsg != null) {
return processValidationErrors("errMsg", errMsg, photoUploadRequest());
}
Photo portrait = albumService.getUserCurrentPortraitPhoto(spotId);
if (portrait == null) {
throw new OperateFailedException("不存在当前图片,无法剪切");
}
long albumId = portrait.getAlbumId();
String smallFile = portrait.getSmallFile();
String ext = portrait.getExt();
String remoteFileKey = smallFile + '.' + ext;
SkylineImageCropTask cropTask = new SkylineImageCropTask(remoteFileKey, portraitSize);
cropTask.setAlbumId(albumId);
cropTask.setUserId(spotId);
cropTask.setOffsetX(x);
cropTask.setOffsetY(y);
cropTask.setCropSize(size);
ImageCropResult cropResult;
try {
cropResult = crop.processImage(basePath, cropTask);
} catch (IOException e) {
throw new OperateFailedException("无法剪切图片");
}
if (cropResult == null || cropResult.getResultState() != ResultState.SUCCESS) {
throw new OperateFailedException("无法剪切图片,原因:"
+ (cropResult == null ? null : cropResult.getResultState()));
}
String portraitFile = cropResult.getFileKey();
spotService.updateSpotPortrait(spotId, portraitFile);