Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

48
LINES

< > BotCompany Repo | #1007145 // quickVisualize

JavaX fragment (include)

sS quickVisualize_progID = #1007145;
static Lock quickVisualize_lock = lock();

static bool quickVisualize_hasCached(S query) {
  ret quickVisualize_imageFile(query).length() != 0;
}

static BufferedImage quickVisualize_fromCache(S query) {
  File f = quickVisualize_imageFile(query);
  if (f.length() != 0) pcall { ret loadPNG(f); }
  null;
}

static S quickVisualize_preprocess(S query) {
  ret toUpper(shorten(trim(query), 200));
}

static BufferedImage quickVisualize(S query) {
  query = quickVisualize_preprocess(query);
  if (empty(query)) null;
  BufferedImage img = quickVisualize_fromCache(query);
  if (img != null) ret img;
  File f = quickVisualize_imageFile(query);
  /*L<S> urls = googleImageSearch_multi(query);
  saveTextFile(quickVisualize_urlsFile(query), joinLines(urls));
  if (empty(urls)) null;
  img = loadBufferedImage(first(urls));*/
  lock quickVisualize_lock;
  img = googleImageSearch_new(query);
  if (img == null) null;
  savePNG(f, img);
  ret img;
}

static S quickVisualize_imagePath(S query) {
  query = quickVisualize_preprocess(query);
  ret fsI(quickVisualize_progID) + "/" + urlencode(query) + ".png";
}

static File quickVisualize_imageFile(S query) {
  query = quickVisualize_preprocess(query);
  ret prepareProgramFile(quickVisualize_progID, urlencode(query) + ".png");
}

static File quickVisualize_urlsFile(S query) {
  query = quickVisualize_preprocess(query);
  ret prepareProgramFile(quickVisualize_progID, "urls-" + urlencode(query) + ".txt");
}

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: 601 / 1292
Version history: 15 change(s)
Referenced in: #1006654 - Standard functions list 2 (LIVE, continuation of #761)
#1007145 - quickVisualize
#1007208 - AI Concepts from tvejysmllsmz
#1007214 - AI Concepts from wtqryiryparv
#1007251 - googleImageSearchFirst - get first inlined image
#1007371 - quickVisualizeOr - quickVisualize with default if search fails
#1007558 - AI Concepts from jtubtzbbkimh
#1007569 - AI Concepts from jtubtzbbkimh
#1016599 - googleImageSearchFirstFullImageURL - get URL of first full-size image
#1025357 - quickVisualize_nsfw