@@ -25,6 +25,8 @@ import ru.soune.nocopy.service.search.SearchImageService;
|
||||
import ru.soune.nocopy.service.tariff.TariffConstants;
|
||||
import ru.soune.nocopy.service.tariff.TariffInfoService;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
@@ -150,7 +152,7 @@ public class ImageFoundRequestHandler implements RequestHandler {
|
||||
String url = image.getUrl();
|
||||
Path tempFile = null;
|
||||
try {
|
||||
tempFile = fileUploadService.downloadImageFromUrl(url);
|
||||
tempFile = convertToSupportedFormat(fileUploadService.downloadImageFromUrl(url));
|
||||
|
||||
String filePath = tempFile.toAbsolutePath().toString();
|
||||
|
||||
@@ -191,4 +193,18 @@ public class ImageFoundRequestHandler implements RequestHandler {
|
||||
return new BaseResponse(request.getMsgId(), MessageCode.SUCCESS.getCode(),
|
||||
message, finalResponse);
|
||||
}
|
||||
|
||||
public Path convertToSupportedFormat(Path imagePath) throws IOException {
|
||||
String fileName = imagePath.getFileName().toString().toLowerCase();
|
||||
|
||||
if (fileName.matches(".*\\.(jpg|jpeg|png|bmp)$")) {
|
||||
return imagePath;
|
||||
}
|
||||
|
||||
BufferedImage image = ImageIO.read(imagePath.toFile());
|
||||
Path pngFile = Files.createTempFile("converted_", ".png");
|
||||
ImageIO.write(image, "PNG", pngFile.toFile());
|
||||
|
||||
return pngFile;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user