From 3c5ec95b59dac6820751a9e3d498cf7bf3538724 Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Mon, 20 Mar 2017 10:32:04 +0300 Subject: Thumbnailator -> imgscalr --- .../main/java/com/juick/api/controllers/Post.java | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) (limited to 'juick-api/src/main') 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 0c93fb7b..322587fb 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 @@ -10,8 +10,9 @@ import com.juick.service.MessagesService; import com.juick.service.SubscriptionService; import com.juick.service.UserService; 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; @@ -24,7 +25,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; @@ -174,12 +177,16 @@ public class Post { Path origName = Paths.get(apiServer.imgDir, "p", fname); Files.move(Paths.get(apiServer.tmpDir, attachmentFName), origName); - Thumbnails.of(origName.toFile()).size(1024, 1024).outputQuality(0.9) - .toFile(Paths.get(apiServer.imgDir, "photos-1024", fname).toFile()); - Thumbnails.of(origName.toFile()).size(512, 512).outputQuality(0.9) - .toFile(Paths.get(apiServer.imgDir, "photos-512", fname).toFile()); - Thumbnails.of(origName.toFile()).size(160, 120).outputQuality(0.9) - .toFile(Paths.get(apiServer.imgDir, "ps", fname).toFile()); + 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()); body = attachmentURL + "\n" + body; try { -- cgit v1.2.3