This repository has been archived by the owner on Jul 13, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #187 from book000/feat/always-embed-textimg
feat: 画像投稿時、同時にtextimgの結果を返すようにする
- Loading branch information
Showing
3 changed files
with
64 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package com.jaoafa.jdavcspeaker.Lib; | ||
|
||
import java.io.BufferedReader; | ||
import java.io.File; | ||
import java.io.IOException; | ||
import java.io.InputStreamReader; | ||
import java.util.List; | ||
import java.util.concurrent.TimeUnit; | ||
import java.util.stream.Collectors; | ||
import java.util.stream.Stream; | ||
|
||
public class LibTextImg { | ||
public static File getTempimgPath(String mediaUrl) throws IOException { | ||
File tmp = File.createTempFile("textimg", ".png"); | ||
Process p; | ||
try { | ||
ProcessBuilder builder = new ProcessBuilder(); | ||
builder.command(List.of("php", "external_scripts/image-text.php", mediaUrl, tmp.getAbsolutePath())); | ||
builder.redirectErrorStream(true); | ||
builder.directory(new File(".")); | ||
p = builder.start(); | ||
boolean bool = p.waitFor(3, TimeUnit.MINUTES); | ||
if (!bool) { | ||
return null; | ||
} | ||
InputStreamReader inputStreamReader = new InputStreamReader(p.getInputStream()); | ||
Stream<String> streamOfString = new BufferedReader(inputStreamReader).lines(); | ||
String streamToString = streamOfString.collect(Collectors.joining("\n")); | ||
System.out.println(streamToString); | ||
if (p.exitValue() != 0) { | ||
return null; | ||
} | ||
} catch (InterruptedException e) { | ||
return null; | ||
} | ||
return tmp; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters