diff options
author | Vitaly Takmazov | 2017-03-20 10:32:04 +0300 |
---|---|---|
committer | Vitaly Takmazov | 2017-03-20 10:32:04 +0300 |
commit | 3c5ec95b59dac6820751a9e3d498cf7bf3538724 (patch) | |
tree | a04e34b01a629fa8fa3d5309b3a0b7898e546c95 | |
parent | 5889ba6af9f5c3cb0391bec8fbbcad0165519738 (diff) |
Thumbnailator -> imgscalr
8 files changed, 77 insertions, 44 deletions
diff --git a/juick-api/build.gradle b/juick-api/build.gradle index 1db46f58..bca3a8c2 100644 --- a/juick-api/build.gradle +++ b/juick-api/build.gradle @@ -16,7 +16,7 @@ dependencies { compile "org.springframework:spring-websocket:${rootProject.springFrameworkVersion}" compile 'com.github.pengrad:java-telegram-bot-api:2.3.1.1' - compile 'net.coobird:thumbnailator:0.4.8' + compile 'org.imgscalr:imgscalr-lib:4.2' providedRuntime 'mysql:mysql-connector-java:5.1.40' testCompile project(path: ':juick-server', configuration: 'testArtifacts') 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 { diff --git a/juick-spring-www/build.gradle b/juick-spring-www/build.gradle index 04a0f724..8c1df178 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 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()); diff --git a/juick-www/build.gradle b/juick-www/build.gradle index 96dcb815..5f42b81b 100644 --- a/juick-www/build.gradle +++ b/juick-www/build.gradle @@ -21,7 +21,7 @@ apply plugin: 'com.github.ben-manes.versions' dependencies { compile project(':juick-server') compile 'com.github.scribejava:scribejava-apis:4.0.0' - compile 'net.coobird:thumbnailator:0.4.8' + compile 'org.imgscalr:imgscalr-lib:4.2' compile 'com.github.ooxi:serialized-php-parser:0.5.0' compile 'com.mitchellbosecke:pebble:2.3.0' compile 'com.sun.mail:javax.mail:1.5.6' 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 938cd338..1993737b 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 f7eb8869..e6e763b1 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()); |