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

问题描述 投票:6回答:2

如果将Prolog HTTP服务器绑定到端口9000的localhost,如何使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'])
    ).

再次感谢您的耐心等待。 :-)

image prolog swi-prolog httpserver
2个回答
7
投票
这是我测试过的代码:

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')都起作用,并且此“功能”有助于模糊界面行为。

这里输出

<< img src =“ https://image.soinside.com/eyJ1cmwiOiAiaHR0cHM6Ly9pLnN0YWNrLmltZ3VyLmNvbS9pb3g0bC5wbmcifQ==” alt =“在此处输入图像描述”>

HTH


1
投票
© www.soinside.com 2019 - 2024. All rights reserved.