aboutsummaryrefslogtreecommitdiff
path: root/juick-api/src/main
diff options
context:
space:
mode:
authorGravatar KillyMXI2017-06-20 01:50:33 +0300
committerGravatar KillyMXI2017-06-20 01:50:33 +0300
commit9943851e037f907623cd879dab2f0e8b31f260cf (patch)
treead479d52100caeed458bd3d626d8432d2eb2e31e /juick-api/src/main
parentf3312679fa538122cd81e0e9a0a251ebb296b80e (diff)
All the image processing is moved to ImageUtils class.
Small images keep their size and do not stretch to 512/1024px.
Diffstat (limited to 'juick-api/src/main')
-rw-r--r--juick-api/src/main/java/com/juick/api/controllers/Post.java21
1 files changed, 2 insertions, 19 deletions
diff --git a/juick-api/src/main/java/com/juick/api/controllers/Post.java b/juick-api/src/main/java/com/juick/api/controllers/Post.java
index 0173cf04..45eb31e7 100644
--- a/juick-api/src/main/java/com/juick/api/controllers/Post.java
+++ b/juick-api/src/main/java/com/juick/api/controllers/Post.java
@@ -6,13 +6,12 @@ import com.juick.server.util.HttpBadRequestException;
import com.juick.server.util.HttpForbiddenException;
import com.juick.server.util.HttpNotFoundException;
import com.juick.server.util.HttpUtils;
+import com.juick.server.util.ImageUtils;
import com.juick.service.MessagesService;
import com.juick.service.SubscriptionService;
import com.juick.service.UserService;
import com.juick.util.UserUtils;
-import org.apache.commons.io.FilenameUtils;
import org.apache.commons.lang3.StringUtils;
-import org.imgscalr.Scalr;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.core.env.Environment;
@@ -25,16 +24,11 @@ import rocks.xmpp.core.stanza.model.Message;
import rocks.xmpp.extensions.nick.model.Nickname;
import rocks.xmpp.extensions.oob.model.x.OobX;
-import javax.imageio.ImageIO;
import javax.inject.Inject;
-import java.awt.image.BufferedImage;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
-import java.nio.file.Files;
-import java.nio.file.Path;
-import java.nio.file.Paths;
/**
* Created by vt on 24/11/2016.
@@ -173,18 +167,7 @@ public class Post {
String fname = mid + "-" + ridnew + "." + attachmentType;
String attachmentURL = "http://i.juick.com/photos-1024/" + fname;
- Path origName = Paths.get(apiServer.imgDir, "p", fname);
- Files.move(Paths.get(apiServer.tmpDir, attachmentFName), origName);
- BufferedImage originalImage = ImageIO.read(origName.toFile());
- ImageIO.write(Scalr.resize(originalImage, 1024),
- FilenameUtils.getExtension(origName.toString()),
- Paths.get(apiServer.imgDir, "photos-1024", fname).toFile());
- ImageIO.write(Scalr.resize(originalImage, 512),
- FilenameUtils.getExtension(origName.toString()),
- Paths.get(apiServer.imgDir, "photos-512", fname).toFile());
- ImageIO.write(Scalr.resize(originalImage, 160),
- FilenameUtils.getExtension(origName.toString()),
- Paths.get(apiServer.imgDir, "ps", fname).toFile());
+ ImageUtils.saveImageWithPreviews(attachmentFName, fname, apiServer.tmpDir, apiServer.imgDir);
body = attachmentURL + "\n" + body;
try {