1 | sS quickVisualize_progID = #1007145; |
2 | static Lock quickVisualize_lock = lock(); |
3 | |
4 | static bool quickVisualize_hasCached(S query) { |
5 | ret quickVisualize_imageFile(query).length() != 0; |
6 | } |
7 | |
8 | static BufferedImage quickVisualize_fromCache(S query) { |
9 | File f = quickVisualize_imageFile(query); |
10 | if (f.length() != 0) pcall { ret loadPNG(f); } |
11 | null; |
12 | } |
13 | |
14 | static S quickVisualize_preprocess(S query) { |
15 | ret toUpper(shorten(trim(query), 200)); |
16 | } |
17 | |
18 | static BufferedImage quickVisualize(S query) { |
19 | query = quickVisualize_preprocess(query); |
20 | if (empty(query)) null; |
21 | BufferedImage img = quickVisualize_fromCache(query); |
22 | if (img != null) ret img; |
23 | File f = quickVisualize_imageFile(query); |
24 | /*L<S> urls = googleImageSearch_multi(query); |
25 | saveTextFile(quickVisualize_urlsFile(query), joinLines(urls)); |
26 | if (empty(urls)) null; |
27 | img = loadBufferedImage(first(urls));*/ |
28 | lock quickVisualize_lock; |
29 | img = googleImageSearch_new(query); |
30 | if (img == null) null; |
31 | savePNG(f, img); |
32 | ret img; |
33 | } |
34 | |
35 | static S quickVisualize_imagePath(S query) { |
36 | query = quickVisualize_preprocess(query); |
37 | ret fsI(quickVisualize_progID) + "/" + urlencode(query) + ".png"; |
38 | } |
39 | |
40 | static File quickVisualize_imageFile(S query) { |
41 | query = quickVisualize_preprocess(query); |
42 | ret prepareProgramFile(quickVisualize_progID, urlencode(query) + ".png"); |
43 | } |
44 | |
45 | static File quickVisualize_urlsFile(S query) { |
46 | query = quickVisualize_preprocess(query); |
47 | ret prepareProgramFile(quickVisualize_progID, "urls-" + urlencode(query) + ".txt"); |
48 | } |
download show line numbers debug dex old transpilations
Travelled to 16 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, iveijnkanddl, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt, whxojlpjdney, xrpafgyirdlv
No comments. add comment
Snippet ID: | #1007145 |
Snippet name: | quickVisualize |
Eternal ID of this version: | #1007145/16 |
Text MD5: | cd9f94b225869b0393a277ec1abe2ad9 |
Author: | stefan |
Category: | javax / imaging / networking |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2019-03-18 10:20:26 |
Source code size: | 1540 bytes / 48 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 717 / 1389 |
Version history: | 15 change(s) |
Referenced in: | [show references] |