gpt4 book ai didi

image - 如何在 Prolog 动态提供的 HTML 页面中包含图像?

转载 作者:行者123 更新时间:2023-12-04 14:30:35 25 4
gpt4 key购买 nike

如果我将我的 Prolog HTTP 服务器绑定(bind)到 localhost在端口 9000,如何让 Prolog 为我的图像生成正确的路径?例如,如果我的 .pl文件和 .jpg.png文件位于桌面上,如何使服务器生成如下 HTML 代码:
<img src="C:\Users\Luka\\Desktop\ImageName.ext"/>ext部分代表扩展。我查看了 SWI-Prolog 和 this tutorial 的文档。 ,但我发现所有这些抽象路径都非常令人困惑。我在 Web 服务器方面有很多经验,但这有很大不同,我在理解它时遇到了可怕的问题。

这是我的尝试,由我在整个 SWI-Prolog 文档和上述教程中学到的(或者至少我认为我已经掌握的)组成:

:- use_module(library(http/thread_httpd)).
:- use_module(library(http/http_dispatch)).
:- use_module(library(http/http_parameters)).
:- use_module(library(http/html_write)).
file_search_path('*', 'C:\\Users\\Luka\\Desktop\\').

server(Port) :-
http_server(http_dispatch, [port(Port)]).

:- http_handler(root(.), render_base, []).
:- http_handler('/form', process_form, []).

process_form(Request) :-
http_parameters(Request,
[name(Name,[atom])]),
reply_html_page('Posted data: ',['',Name]).

render_base(_Request) :-
reply_html_page(
title('Naslov'),
img([src='/image.png', alt='Incident'])
).

再次提前感谢您的巨大耐心。 :-)

最佳答案

确实,解决您的问题并不简单。请仔细阅读this “如何”页面,部分 Serving many 'server support' files .

这是我测试的代码:

http:location(images, root(images), []).
user:file_search_path(icons, '/home/carlo/prolog').
:- http_handler(images(.), serve_files_in_directory(icons), [prefix]).

以及使用该资源的 HTML
intro -->
html([p(ol([li('select a path'),
li('scan resources from it'),
li('RDF-ize them'),
li('browse with foldable SVG')
])),
\sep,
'png before', img(src='images/swipl.png'), 'png after',
\sep,
'jpeg before', img(src='/images/swipl.jpeg'), 'jpeg after'
]).

我注意到这两个规范 img(src='images/swipl.png')img(src='/images/swipl.jpeg')工作,这个“功能”有助于模糊界面行为。

这里的输出

enter image description here

高温高压

关于image - 如何在 Prolog 动态提供的 HTML 页面中包含图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14394347/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com