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 /juick-api/src/main/java/com/juick | |
parent | f3fce84310a189d9be295268e3207d392509e466 (diff) |
convert.sh -> Thumbnailator (www, api)
Diffstat (limited to 'juick-api/src/main/java/com/juick')
-rw-r--r-- | juick-api/src/main/java/com/juick/api/Main.java | 27 |
1 files changed, 24 insertions, 3 deletions
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(); |