diff options
Diffstat (limited to 'juick-spring-www')
3 files changed, 31 insertions, 18 deletions
diff --git a/juick-spring-www/build.gradle b/juick-spring-www/build.gradle index 04a0f7240..8c1df1787 100644 --- a/juick-spring-www/build.gradle +++ b/juick-spring-www/build.gradle @@ -32,8 +32,7 @@ dependencies { compile "org.thymeleaf.extras:thymeleaf-extras-springsecurity4:3.0.2.RELEASE" compile "nz.net.ultraq.thymeleaf:thymeleaf-layout-dialect:2.2.1" - compile 'net.coobird:thumbnailator:0.4.8' - + compile 'org.imgscalr:imgscalr-lib:4.2' testCompile "junit:junit:${rootProject.junitVersion}" testCompile "org.hamcrest:hamcrest-all:${rootProject.hamcrestVersion}" testCompile "org.mockito:mockito-core:${rootProject.mockitoVersion}" 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 954047325..8ad064023 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 d1c872d7e..58668dc19 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()); |