diff options
author | Vitaly Takmazov | 2016-07-25 11:27:38 +0300 |
---|---|---|
committer | Vitaly Takmazov | 2016-07-27 13:55:51 +0300 |
commit | 94c0d43d2765488d715bffe426934ed7caa8f4f2 (patch) | |
tree | 400e3aa57d9aa09c0ae4312b67334d01efc23dfa | |
parent | f3fce84310a189d9be295268e3207d392509e466 (diff) |
convert.sh -> Thumbnailator (www, api)
-rw-r--r-- | juick-api/build.gradle | 1 | ||||
-rw-r--r-- | juick-api/src/main/java/com/juick/api/Main.java | 27 | ||||
-rw-r--r-- | juick-www/src/main/java/com/juick/www/NewMessage.java | 9 |
3 files changed, 33 insertions, 4 deletions
diff --git a/juick-api/build.gradle b/juick-api/build.gradle index 4b8ce36a..0fc56186 100644 --- a/juick-api/build.gradle +++ b/juick-api/build.gradle @@ -27,6 +27,7 @@ dependencies { compile 'org.msbotframework4j:msbotframework4j-builder:0.1.4' compile 'com.neovisionaries:nv-websocket-client:1.27' compile 'org.apache.commons:commons-dbcp2:2.0' + compile 'net.coobird:thumbnailator:0.4.8' providedRuntime 'mysql:mysql-connector-java:5.1.39' } compileJava.options.encoding = 'UTF-8' diff --git a/juick-api/src/main/java/com/juick/api/Main.java b/juick-api/src/main/java/com/juick/api/Main.java index 676aab79..47c4e448 100644 --- a/juick-api/src/main/java/com/juick/api/Main.java +++ b/juick-api/src/main/java/com/juick/api/Main.java @@ -30,6 +30,7 @@ import com.juick.xmpp.StreamComponent; import com.juick.xmpp.extensions.JuickMessage; import com.juick.xmpp.extensions.Nickname; import com.juick.xmpp.extensions.XOOB; +import net.coobird.thumbnailator.Thumbnails; import org.apache.commons.dbcp2.BasicDataSource; import org.springframework.jdbc.core.JdbcTemplate; @@ -44,6 +45,9 @@ import java.io.PrintWriter; import java.lang.reflect.InvocationTargetException; import java.net.Socket; import java.net.URL; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; import java.util.ArrayList; import java.util.List; import java.util.Properties; @@ -68,6 +72,8 @@ public class Main extends HttpServlet implements Stream.StreamListener { TelegramBotHook tgb; SkypeEndpoint sep; + String tmpDir, imgDir; + @Override public void init() throws ServletException { super.init(); @@ -87,7 +93,8 @@ public class Main extends HttpServlet implements Stream.StreamListener { sep = new SkypeEndpoint(); setupXmppComponent(conf.getProperty("xmpp_host", "localhost"), Integer.parseInt(conf.getProperty("xmpp_port", "5347")), conf.getProperty("xmpp_jid", "api.localhost"), conf.getProperty("xmpp_password")); - + tmpDir = conf.getProperty("upload_tmp_dir", "/var/www/juick.com/i/tmp/"); + imgDir = conf.getProperty("img_path", "/var/www/juick.com/i/"); } catch (IOException e) { log("API initialization error", e); } @@ -301,7 +308,14 @@ public class Main extends HttpServlet implements Stream.StreamListener { String fname = mid + "." + attachmentType; String attachmentURL = "http://i.juick.com/photos-1024/" + fname; - Runtime.getRuntime().exec("/var/www/juick.com/cgi/p-convert.sh /var/www/juick.com/i/tmp/" + attachmentFName + " " + fname); + Path origName = Paths.get(imgDir, "p", fname); + Files.move(Paths.get(tmpDir, attachmentFName), origName); + Thumbnails.of(origName.toFile()).size(1024, 1024).outputQuality(0.9) + .toFile(Paths.get(imgDir, "photos-1024", fname).toFile()); + Thumbnails.of(origName.toFile()).size(512, 512).outputQuality(0.9) + .toFile(Paths.get(imgDir, "photos-512", fname).toFile()); + Thumbnails.of(origName.toFile()).size(160, 120).outputQuality(0.9) + .toFile(Paths.get(imgDir, "ps", fname).toFile()); body = attachmentURL + "\n" + body; XOOB xoob = new XOOB(); @@ -422,7 +436,14 @@ public class Main extends HttpServlet implements Stream.StreamListener { String fname = mid + "-" + ridnew + "." + attachmentType; String attachmentURL = "http://i.juick.com/photos-1024/" + fname; - Runtime.getRuntime().exec("/var/www/juick.com/cgi/p-convert.sh /var/www/juick.com/i/tmp/" + attachmentFName + " " + fname); + Path origName = Paths.get(imgDir, "p", fname); + Files.move(Paths.get(tmpDir, attachmentFName), origName); + Thumbnails.of(origName.toFile()).size(1024, 1024).outputQuality(0.9) + .toFile(Paths.get(imgDir, "photos-1024", fname).toFile()); + Thumbnails.of(origName.toFile()).size(512, 512).outputQuality(0.9) + .toFile(Paths.get(imgDir, "photos-512", fname).toFile()); + Thumbnails.of(origName.toFile()).size(160, 120).outputQuality(0.9) + .toFile(Paths.get(imgDir, "ps", fname).toFile()); body = attachmentURL + "\n" + body; XOOB xoob = new XOOB(); diff --git a/juick-www/src/main/java/com/juick/www/NewMessage.java b/juick-www/src/main/java/com/juick/www/NewMessage.java index c6a1aae8..d64fce78 100644 --- a/juick-www/src/main/java/com/juick/www/NewMessage.java +++ b/juick-www/src/main/java/com/juick/www/NewMessage.java @@ -214,7 +214,14 @@ public class NewMessage { String fname = mid + "." + attachmentType; String attachmentURL = "http://i.juick.com/photos-1024/" + fname; - Runtime.getRuntime().exec("/var/www/juick.com/cgi/p-convert.sh /var/www/juick.com/i/tmp/" + attachmentFName + " " + fname); + Path origName = Paths.get(imgDir, "p", fname); + Files.move(Paths.get(tmpDir, attachmentFName), origName); + Thumbnails.of(origName.toFile()).size(1024, 1024).outputQuality(0.9) + .toFile(Paths.get(imgDir, "photos-1024", fname).toFile()); + Thumbnails.of(origName.toFile()).size(512, 512).outputQuality(0.9) + .toFile(Paths.get(imgDir, "photos-512", fname).toFile()); + Thumbnails.of(origName.toFile()).size(160, 120).outputQuality(0.9) + .toFile(Paths.get(imgDir, "ps", fname).toFile()); body = attachmentURL + "\n" + body; XOOB xoob = new XOOB(); |