# Dynamic WebImageSearch

I am a little bit lost here, I'd be really grateful if someone could help me. :) We are working on a "video" (actually images with transitions).

We are having a list of specific words eg.:

List = {apple, tree, house, dog}


(but these words can change every time when we import an another text), so everything is pretty much dynamic.

So that we are having a specific list of words and we would like to use these words to find images this way:

WebImageSearch["word1", "Thumbnails", "MaxItems" -> 1]
WebImageSearch["word2", "Thumbnails", "MaxItems" -> 1]
WebImageSearch["word3", "Thumbnails", "MaxItems" -> 1]


... so that, I guess:

WebImageSearch[dynamic-image, "Thumbnails", "MaxItems" -> 1]


where dynamic-image has to be dynamic.

Also is it possible to do it with not WebImageSearch, but something free (eg. with an api)? That would be absolutely be the best! :)

Thanks you very much in advance!

### Update:

here's the same, but better and in a package on GitHub now:

Get["https://raw.githubusercontent.com/b3m2a1/mathematica-tools/master/DynamicWebImage.wl"]

i = Last[animals];
DynamicWebImageBrowser[Dynamic[i], animals]


Here's a way to do this for free with the Qwant API:

dynamicWebImage[
imgVar_Dynamic,
caching : True | False : True,
ops : OptionsPattern[Join[Options@DynamicModule, Options@Image]]
] :=
DynamicModule[
{img},
Replace[
imgVar, {
Verbatim[Dynamic][var_, o___?OptionQ] :>
Dynamic[
img =
Image[
dynamicWebImagePrivateqwantSingleSearch[var, caching]["Image"],
FilterRules[{ops},
Options@Image
]
],
o],
Verbatim[Dynamic][var_, f : Except[_?OptionQ], o___?OptionQ] :>
Dynamic[
img =
Image[
Last@Through[

Flatten[List@f][
dynamicWebImagePrivateqwantSingleSearch[var, caching]]
],
FilterRules[{ops},
Options@Image
]
],
o
]
}],
Initialization :>
{
OptionValue[Initialization],
If[! AssociationQ@dynamicWebImagePrivate$qwantCache, dynamicWebImagePrivate$qwantCache = <||>
],
dynamicWebImagePrivateqwantSingleSearch[
q_String?(StringLength[StringTrim[#]] > 0 &),
cached : True | False : True] :=
Replace[
dynamicWebImagePrivate$qwantCache[q], Except[_Association?(KeyMemberQ["Image"])]:> With[{ r = First@Normal@ dynamicWebImagePrivateqwantInstance["ImageSearch", "q" -> q, "count" -> "1"] }, If[cached, dynamicWebImagePrivate$qwantCache[q] = r, r]
]
],
dynamicWebImagePrivateqwantSingleSearch[__] :=
None,
If[! TrueQ[dynamicWebImagePrivateqwantPacletUpdated],
If[Length@PacletManagerPacletFind["ServiceConnection_Qwant"] > 0,
PacletInstall,
PacletUpdate
][
"ServiceConnection_Qwant",
"Site" ->
"https://www.wolframcloud.com/objects/b3m2a1.paclets/\
PacletServer"
];
dynamicWebImagePrivateqwantPacletUpdated =
Length@PacletManagerPacletFind["ServiceConnection_Qwant"] > 0
],
dynamicWebImagePrivateqwantInstance = ServiceConnect["Qwant"]
},
Evaluate[
Sequence @@ FilterRules[{
ops
},
Options@DynamicModule
]
],
SynchronousInitialization->True
]


This just sets up a little framework to work with this answer.

Here's a fun example of what you can do with it:

animals =
Cases[
Import[
"https://www.livescience.com/13524-500-cutest-animals-list.html",
{"HTML", "XMLObject"}
],
XMLElement["p", _,
{a_String?(StringStartsQ[Whitespace ~~ DigitCharacter .. ~~ "."])}
] :>
StringTrim@
First@StringSplit[Last@StringSplit[a, ". "], "(" | " aka "],
\[Infinity]];
a = Last@animals;

Framed[
Column[{
Panel[
InputField[Dynamic[a],
String,
],
ImageSize -> 350,
Appearance ->
Lookup[
FrontEndResource["FEExpressions",
"MoreLeftSetterNinePatchAppearance"],
"Hover"
],
Alignment -> Center
],
dynamicWebImage[
Dynamic[a],
ImageSize -> 350,
DynamicEvaluationTimeout -> Infinity
]
},
Spacings -> 0
],
FrameMargins -> None,
FrameStyle -> GrayLevel[.85]
]


Note that that's really just so much formatting around:

dynamicWebImage[
Dynamic[a],
ImageSize -> 350,
DynamicEvaluationTimeout -> Infinity
]

• Comments are not for extended discussion; this conversation has been moved to chat. – Kuba Nov 22 '17 at 6:50