public Optional<String> toImageBlock(List<File> dropFiles) { if (!current.currentPath().isPresent()) asciiDocController.saveDoc(); Path currentPath = current.currentPath().map(Path::getParent).get(); IOHelper.createDirectories(currentPath.resolve("images")); List<Path> paths = dropFiles .stream() .map(File::toPath) .filter(pathResolver::isImage) .collect(Collectors.toList()); List<String> buffer = new LinkedList<>(); for (Path path : paths) { Path targetImage = currentPath.resolve("images").resolve(path.getFileName()); if (!path.equals(targetImage)) IOHelper.copy(path, targetImage); buffer.add(String.format("image::images/%s[]", path.getFileName())); } if (buffer.size() > 0) return Optional.of(String.join("\n", buffer)); return Optional.empty(); }
public Optional<String> toImageBlock(Image image) { if (!current.currentPath().isPresent()) asciiDocController.saveDoc(); Path currentPath = current.currentPath().map(Path::getParent).get(); IOHelper.createDirectories(currentPath.resolve("images")); List<String> buffer = new LinkedList<>(); DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern(asciiDocController.getClipboardImageFilePattern()); Path path = Paths.get(dateTimeFormatter.format(LocalDateTime.now())); Path targetImage = currentPath.resolve("images").resolve(path.getFileName()); try { BufferedImage fromFXImage = SwingFXUtils.fromFXImage(image, null); ImageIO.write(fromFXImage, "png", targetImage.toFile()); } catch (Exception e) { logger.error("Problem occured while saving clipboard image {}", targetImage); } buffer.add(String.format("image::images/%s[]", path.getFileName())); if (buffer.size() > 0) return Optional.of(String.join("\n", buffer)); return Optional.empty(); }