aboutsummaryrefslogtreecommitdiff
path: root/juick-www/src/main/java/com/juick/www/controllers
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2017-03-20 10:32:04 +0300
committerGravatar Vitaly Takmazov2017-03-20 10:32:04 +0300
commit3c5ec95b59dac6820751a9e3d498cf7bf3538724 (patch)
treea04e34b01a629fa8fa3d5309b3a0b7898e546c95 /juick-www/src/main/java/com/juick/www/controllers
parent5889ba6af9f5c3cb0391bec8fbbcad0165519738 (diff)
Thumbnailator -> imgscalr
Diffstat (limited to 'juick-www/src/main/java/com/juick/www/controllers')
-rw-r--r--juick-www/src/main/java/com/juick/www/controllers/NewMessage.java38
-rw-r--r--juick-www/src/main/java/com/juick/www/controllers/Settings.java9
2 files changed, 30 insertions, 17 deletions
diff --git a/juick-www/src/main/java/com/juick/www/controllers/NewMessage.java b/juick-www/src/main/java/com/juick/www/controllers/NewMessage.java
index 938cd3386..1993737bf 100644
--- a/juick-www/src/main/java/com/juick/www/controllers/NewMessage.java
+++ b/juick-www/src/main/java/com/juick/www/controllers/NewMessage.java
@@ -24,11 +24,12 @@ import com.juick.server.util.HttpUtils;
import com.juick.service.*;
import com.juick.www.Utils;
import com.juick.www.WebApp;
-import net.coobird.thumbnailator.Thumbnails;
+import org.apache.commons.io.FilenameUtils;
import org.apache.commons.lang3.CharEncoding;
import org.apache.commons.lang3.StringEscapeUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.math.NumberUtils;
+import org.imgscalr.Scalr;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.core.env.Environment;
@@ -42,9 +43,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 javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
+import java.awt.image.BufferedImage;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.UnsupportedEncodingException;
@@ -225,12 +228,16 @@ public class NewMessage {
Path origName = Paths.get(webApp.getImgDir(), "p", fname);
Files.move(Paths.get(webApp.getTmpDir(), attachmentFName), origName);
- Thumbnails.of(origName.toFile()).size(1024, 1024).outputQuality(0.9)
- .toFile(Paths.get(webApp.getImgDir(), "photos-1024", fname).toFile());
- Thumbnails.of(origName.toFile()).size(512, 512).outputQuality(0.9)
- .toFile(Paths.get(webApp.getImgDir(), "photos-512", fname).toFile());
- Thumbnails.of(origName.toFile()).size(160, 120).outputQuality(0.9)
- .toFile(Paths.get(webApp.getImgDir(), "ps", fname).toFile());
+ BufferedImage originalImage = ImageIO.read(origName.toFile());
+ ImageIO.write(Scalr.resize(originalImage, 1024),
+ FilenameUtils.getExtension(origName.toString()),
+ Paths.get(webApp.getImgDir(), "photos-1024", fname).toFile());
+ ImageIO.write(Scalr.resize(originalImage, 512),
+ FilenameUtils.getExtension(origName.toString()),
+ Paths.get(webApp.getImgDir(), "photos-512", fname).toFile());
+ ImageIO.write(Scalr.resize(originalImage, 160),
+ FilenameUtils.getExtension(origName.toString()),
+ Paths.get(webApp.getImgDir(), "ps", fname).toFile());
body = attachmentURL + "\n" + body;
try {
@@ -386,13 +393,16 @@ public class NewMessage {
Path origName = Paths.get(webApp.getImgDir(), "p", fname);
Files.move(Paths.get(webApp.getTmpDir(), attachmentFName), origName);
- Thumbnails.of(origName.toFile()).size(1024, 1024).outputQuality(0.9)
- .toFile(Paths.get(webApp.getImgDir(), "photos-1024", fname).toFile());
- Thumbnails.of(origName.toFile()).size(512, 512).outputQuality(0.9)
- .toFile(Paths.get(webApp.getImgDir(), "photos-512", fname).toFile());
- Thumbnails.of(origName.toFile()).size(160, 120).outputQuality(0.9)
- .toFile(Paths.get(webApp.getImgDir(), "ps", fname).toFile());
-
+ BufferedImage originalImage = ImageIO.read(origName.toFile());
+ ImageIO.write(Scalr.resize(originalImage, 1024),
+ FilenameUtils.getExtension(origName.toString()),
+ Paths.get(webApp.getImgDir(), "photos-1024", fname).toFile());
+ ImageIO.write(Scalr.resize(originalImage, 512),
+ FilenameUtils.getExtension(origName.toString()),
+ Paths.get(webApp.getImgDir(), "photos-512", fname).toFile());
+ ImageIO.write(Scalr.resize(originalImage, 160),
+ FilenameUtils.getExtension(origName.toString()),
+ Paths.get(webApp.getImgDir(), "ps", fname).toFile());
body = attachmentURL + "\n" + body;
try {
xmsg.addExtension(new OobX(new URI(attachmentURL)));
diff --git a/juick-www/src/main/java/com/juick/www/controllers/Settings.java b/juick-www/src/main/java/com/juick/www/controllers/Settings.java
index f7eb8869e..e6e763b19 100644
--- a/juick-www/src/main/java/com/juick/www/controllers/Settings.java
+++ b/juick-www/src/main/java/com/juick/www/controllers/Settings.java
@@ -24,9 +24,9 @@ import com.juick.server.util.HttpUtils;
import com.juick.service.*;
import com.juick.util.UserUtils;
import com.juick.www.WebApp;
-import net.coobird.thumbnailator.Thumbnails;
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.dao.EmptyResultDataAccessException;
@@ -37,6 +37,7 @@ import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.multipart.MultipartFile;
+import javax.imageio.ImageIO;
import javax.inject.Inject;
import javax.mail.Message;
import javax.mail.MessagingException;
@@ -48,6 +49,7 @@ import javax.servlet.ServletException;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
+import java.awt.image.BufferedImage;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
@@ -174,8 +176,9 @@ public class Settings {
Path a = Paths.get(webApp.getImgDir(), "a", targetName);
Path as = Paths.get(webApp.getImgDir(), "as", targetName);
Files.move(Paths.get(webApp.getTmpDir(), avatarTmpPath), ao, StandardCopyOption.REPLACE_EXISTING);
- Thumbnails.of(ao.toFile()).size(96, 96).toFile(a.toFile());
- Thumbnails.of(ao.toFile()).size(32, 32).toFile(as.toFile());
+ BufferedImage originalImage = ImageIO.read(ao.toFile());
+ ImageIO.write(Scalr.resize(originalImage, 96), "png", a.toFile());
+ ImageIO.write(Scalr.resize(originalImage, 32), "png", as.toFile());
}
if (userService.updateUserInfo(visitor, info)) {
result = String.format("<p>Your info is updated.</p><p><a href='/%s/'>Back to blog</a>.</p>", visitor.getName());