aboutsummaryrefslogtreecommitdiff
path: root/juick-spring-www/src/main/java/com/juick/www
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-spring-www/src/main/java/com/juick/www
parent5889ba6af9f5c3cb0391bec8fbbcad0165519738 (diff)
Thumbnailator -> imgscalr
Diffstat (limited to 'juick-spring-www/src/main/java/com/juick/www')
-rw-r--r--juick-spring-www/src/main/java/com/juick/www/controllers/PostController.java37
-rw-r--r--juick-spring-www/src/main/java/com/juick/www/controllers/SettingsController.java9
2 files changed, 30 insertions, 16 deletions
diff --git a/juick-spring-www/src/main/java/com/juick/www/controllers/PostController.java b/juick-spring-www/src/main/java/com/juick/www/controllers/PostController.java
index 95404732..8ad06402 100644
--- a/juick-spring-www/src/main/java/com/juick/www/controllers/PostController.java
+++ b/juick-spring-www/src/main/java/com/juick/www/controllers/PostController.java
@@ -12,9 +12,10 @@ import com.juick.service.TagService;
import com.juick.service.UserService;
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.CharEncoding;
import org.apache.commons.lang3.StringUtils;
+import org.imgscalr.Scalr;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.core.env.Environment;
@@ -29,7 +30,9 @@ 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;
@@ -106,12 +109,16 @@ public class PostController {
Path origName = Paths.get(webApp.imgDir, "p", fname);
Files.move(Paths.get(webApp.tmpDir, attachmentFName), origName);
- Thumbnails.of(origName.toFile()).size(1024, 1024).outputQuality(0.9)
- .toFile(Paths.get(webApp.imgDir, "photos-1024", fname).toFile());
- Thumbnails.of(origName.toFile()).size(512, 512).outputQuality(0.9)
- .toFile(Paths.get(webApp.imgDir, "photos-512", fname).toFile());
- Thumbnails.of(origName.toFile()).size(160, 120).outputQuality(0.9)
- .toFile(Paths.get(webApp.imgDir, "ps", fname).toFile());
+ BufferedImage originalImage = ImageIO.read(origName.toFile());
+ ImageIO.write(Scalr.resize(originalImage, 1024),
+ FilenameUtils.getExtension(origName.toString()),
+ Paths.get(webApp.imgDir, "photos-1024", fname).toFile());
+ ImageIO.write(Scalr.resize(originalImage, 512),
+ FilenameUtils.getExtension(origName.toString()),
+ Paths.get(webApp.imgDir, "photos-512", fname).toFile());
+ ImageIO.write(Scalr.resize(originalImage, 160),
+ FilenameUtils.getExtension(origName.toString()),
+ Paths.get(webApp.imgDir, "ps", fname).toFile());
body = attachmentURL + "\n" + body;
try {
@@ -238,12 +245,16 @@ public class PostController {
Path origName = Paths.get(webApp.imgDir, "p", fname);
Files.move(Paths.get(webApp.tmpDir, attachmentFName), origName);
- Thumbnails.of(origName.toFile()).size(1024, 1024).outputQuality(0.9)
- .toFile(Paths.get(webApp.imgDir, "photos-1024", fname).toFile());
- Thumbnails.of(origName.toFile()).size(512, 512).outputQuality(0.9)
- .toFile(Paths.get(webApp.imgDir, "photos-512", fname).toFile());
- Thumbnails.of(origName.toFile()).size(160, 120).outputQuality(0.9)
- .toFile(Paths.get(webApp.imgDir, "ps", fname).toFile());
+ BufferedImage originalImage = ImageIO.read(origName.toFile());
+ ImageIO.write(Scalr.resize(originalImage, 1024),
+ FilenameUtils.getExtension(origName.toString()),
+ Paths.get(webApp.imgDir, "photos-1024", fname).toFile());
+ ImageIO.write(Scalr.resize(originalImage, 512),
+ FilenameUtils.getExtension(origName.toString()),
+ Paths.get(webApp.imgDir, "photos-512", fname).toFile());
+ ImageIO.write(Scalr.resize(originalImage, 160),
+ FilenameUtils.getExtension(origName.toString()),
+ Paths.get(webApp.imgDir, "ps", fname).toFile());
body = attachmentURL + "\n" + body;
try {
diff --git a/juick-spring-www/src/main/java/com/juick/www/controllers/SettingsController.java b/juick-spring-www/src/main/java/com/juick/www/controllers/SettingsController.java
index d1c872d7..58668dc1 100644
--- a/juick-spring-www/src/main/java/com/juick/www/controllers/SettingsController.java
+++ b/juick-spring-www/src/main/java/com/juick/www/controllers/SettingsController.java
@@ -8,9 +8,9 @@ import com.juick.server.util.HttpForbiddenException;
import com.juick.server.util.HttpUtils;
import com.juick.service.*;
import com.juick.util.UserUtils;
-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.core.env.Environment;
@@ -22,6 +22,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;
@@ -31,6 +32,7 @@ import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletResponse;
+import java.awt.image.BufferedImage;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
@@ -162,8 +164,9 @@ public class SettingsController {
Path a = Paths.get(imgPath, "a", targetName);
Path as = Paths.get(imgPath, "as", targetName);
Files.move(Paths.get(tmpDir, 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());