TASK: 使用Flux生成前,to Product Image,为输入透明图添加白色背景
This commit is contained in:
@@ -65,6 +65,7 @@ import java.util.regex.Pattern;
|
||||
|
||||
import static com.ai.da.common.enums.CollectionLevel1TypeEnum.*;
|
||||
import static com.ai.da.common.enums.CreditsEventsEnum.TO_PRODUCT_IMAGE;
|
||||
import static com.ai.da.common.enums.CreditsEventsEnum.TO_PRODUCT_IMAGE_FLUX;
|
||||
|
||||
@Slf4j
|
||||
@Service
|
||||
@@ -2119,7 +2120,13 @@ public class GenerateServiceImpl extends ServiceImpl<GenerateMapper, Generate> i
|
||||
|
||||
if (!StringUtil.isNullOrEmpty(imagePath)){
|
||||
try {
|
||||
String imageAsBase64 = minioUtil.getImageAsBase64(imagePath);
|
||||
String imageAsBase64 = null;
|
||||
if (func.equals(TO_PRODUCT_IMAGE_FLUX)){
|
||||
imageAsBase64 = addWhiteBackground(imagePath);
|
||||
}
|
||||
if (StringUtil.isNullOrEmpty(imageAsBase64)){
|
||||
imageAsBase64 = minioUtil.getImageAsBase64(imagePath);
|
||||
}
|
||||
requestBody.set("input_image", imageAsBase64);
|
||||
} catch (IOException e) {
|
||||
log.error("获取图片的base64格式失败,{}", String.valueOf(e));
|
||||
@@ -2220,5 +2227,16 @@ public class GenerateServiceImpl extends ServiceImpl<GenerateMapper, Generate> i
|
||||
}
|
||||
}
|
||||
|
||||
private String addWhiteBackground(String minioPath){
|
||||
// 1、先通过后缀判断输入图片类型有没有透明通道
|
||||
String extension = minioPath.substring(minioPath.lastIndexOf(".") + 1);
|
||||
|
||||
// 2、如果有,为其添加白色背景
|
||||
if (extension.equals("png")){
|
||||
return minioUtil.changeToWhiteBackground(minioPath);
|
||||
}else {
|
||||
log.info("图片 {} 没有透明通道, 不用添加白底", minioPath);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user