diff options
Diffstat (limited to 'juick-common/src/main/java/com/juick/service')
-rw-r--r-- | juick-common/src/main/java/com/juick/service/ImagesService.java | 17 | ||||
-rw-r--r-- | juick-common/src/main/java/com/juick/service/ImagesServiceImpl.java | 31 |
2 files changed, 36 insertions, 12 deletions
diff --git a/juick-common/src/main/java/com/juick/service/ImagesService.java b/juick-common/src/main/java/com/juick/service/ImagesService.java index b5cff16e..192217fe 100644 --- a/juick-common/src/main/java/com/juick/service/ImagesService.java +++ b/juick-common/src/main/java/com/juick/service/ImagesService.java @@ -2,6 +2,23 @@ package com.juick.service; import com.juick.Message; +import java.io.IOException; + public interface ImagesService { void setAttachmentMetadata(String imgDir, String baseUrl, Message msg) throws Exception; + /** + * Move attached image from temp folder to image folder. + * Create preview images in corresponding folders. + * + * @param tempFilename Name of the image file in the temp folder. + * @param outputFilename Name that will be used in the image folder. + */ + void saveImageWithPreviews(String tempFilename, String outputFilename) throws IOException; + /** + * Save new avatar in all required sizes. + * + * @param tempFilename Name of the image file in the temp folder. + * @param uid User id that is used to build image file names. + */ + void saveAvatar(String tempFilename, int uid) throws IOException; } diff --git a/juick-common/src/main/java/com/juick/service/ImagesServiceImpl.java b/juick-common/src/main/java/com/juick/service/ImagesServiceImpl.java index 3a5c77dd..dbc3f3a9 100644 --- a/juick-common/src/main/java/com/juick/service/ImagesServiceImpl.java +++ b/juick-common/src/main/java/com/juick/service/ImagesServiceImpl.java @@ -7,9 +7,14 @@ import com.juick.server.util.ImageUtils; import org.springframework.util.StringUtils; import java.io.File; +import java.io.IOException; import java.nio.file.Paths; public class ImagesServiceImpl implements ImagesService { + private ImageUtils imageUtils; + public ImagesServiceImpl(String imgDir, String tmpDir) { + imageUtils = new ImageUtils(imgDir, tmpDir); + } @Override public void setAttachmentMetadata(String imgDir, String baseUrl, Message msg) throws Exception { if (!StringUtils.isEmpty(msg.getAttachmentType())) { @@ -42,30 +47,32 @@ public class ImagesServiceImpl implements ImagesService { builder.append(".").append(msg.getAttachmentType()); String originalUrl = builder.toString(); - Attachment original = new Attachment(); + Attachment original = imageUtils.getAttachment(fullImage); original.setUrl(originalUrl); - original.setHeight(ImageUtils.getImageHeight(fullImage)); - original.setWidth(ImageUtils.getImageWidth(fullImage)); - Attachment medium = new Attachment(); + Attachment medium = imageUtils.getAttachment(mediumImage); medium.setUrl(photo.getMedium()); - medium.setWidth(ImageUtils.getImageWidth(mediumImage)); - medium.setHeight(ImageUtils.getImageHeight(mediumImage)); original.setMedium(medium); - Attachment small = new Attachment(); + Attachment small = imageUtils.getAttachment(smallImage); small.setUrl(photo.getSmall()); - small.setWidth(ImageUtils.getImageWidth(smallImage)); - small.setHeight(ImageUtils.getImageHeight(smallImage)); original.setSmall(small); - Attachment thumb = new Attachment(); + Attachment thumb = imageUtils.getAttachment(thumbnailImage); thumb.setUrl(photo.getMedium()); - thumb.setWidth(ImageUtils.getImageWidth(thumbnailImage)); - thumb.setHeight(ImageUtils.getImageHeight(thumbnailImage)); original.setThumbnail(thumb); msg.setAttachment(original); } } + + @Override + public void saveImageWithPreviews(String tempFilename, String outputFilename) throws IOException { + imageUtils.saveImageWithPreviews(tempFilename, outputFilename); + } + + @Override + public void saveAvatar(String tempFilename, int uid) throws IOException { + imageUtils.saveAvatar(tempFilename, uid); + } } |