Return with an image from an asset folder within a package

Hello,

I am working on my first package.
I wish to add a few functions returning an image or some data taken from within the package itself.
For example, I want to display an image in an HTML as shown here:

function nbHeader(subject; logowidth=80)
    logo = "???"
    
    html = """
    <h1>myPackage.jl</h1>
    <img src="$(logo)" width="$(logowidth)">   
    <h2>$subject</h2>
    """
    
    HTML(html)
end

I have tried several options, like absolute path, relative path, url on github, url from webio, …
The most I tried to more fuzzy it becomes!

What is the best way to do that?
The requirement is that when the package is installed somewhere (local machine or server, cloud, …) it will display the image when used from Jupyter or Pluto or anything else.
It seems an url on github will always work, but I don’t like this solution.
I prefer to take the image (or data) from within the package itself (asset).

Thanks for your suggestions

Michel

I don’t know the html aspects but the normal way of getting the path to a file in the package is to do

joinpath(@__DIR__, relative_path)

where @__DIR__ gives you the directory of the file of the code.

1 Like

Would joinpath(pkgdir(Foo), "image.png"), where Foo is the name of your package work?

Edit: ninja‘d

1 Like

Thanks Gunnar

Will that also work when it run from Binder of JuliaHub for example?
I ask because this will be a filepath on a server, not an url.
Would that be ok?

Thanks

Michel

I’ll pass on that question. Web technologies isn’t my area.

1 Like