diff options
author | 2018-04-11 14:05:43 +0300 | |
---|---|---|
committer | 2018-04-11 14:05:43 +0300 | |
commit | f7a2f1440ef0c13a472b1b815186615d2c54168a (patch) | |
tree | 2270b2bd9948cdb809e40942b63cf4c84172a53a /juick-common/src/main/java/com/juick/service/ImagesServiceImpl.java | |
parent | 6f346454e906d07551c35a7173fd8175b4d0975d (diff) |
server: ImagesService refactoring
Diffstat (limited to 'juick-common/src/main/java/com/juick/service/ImagesServiceImpl.java')
-rw-r--r-- | juick-common/src/main/java/com/juick/service/ImagesServiceImpl.java | 31 |
1 files changed, 19 insertions, 12 deletions
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); + } } |