Cannot include image from sub-sections

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Cannot include image from sub-sections

thierryler
I wrote a document with included sections with this structure :

    mydoc.adocs
    chap1/
      |---- chap1.adoc
      |---- sections/
                | ---- section1.adoc
                | ---- images/
                         | ---- myimg.png
    img/
      | ---- foo.jpg

I generate my PDF with the following command :

    asciidoctor-pdf -b pdf mydoc.adoc

The mydoc.adoc looks like this :

    :doctype: book
    :encoding: utf-8
    :imagesdir: img

    = My life...
    Thierry <thierry@mywebsite.com>

    include::chap1/chap1.adoc[]

The chap1.adoc looks like this :

    [[_Chap1]]
    == Foo
    include::sections/section1.adoc[]

And finally the section1.adoc looks like this :

    === Some title
    image::../images/myimg.png[photo of me]

If I generate the PDF for section1.adoc (asciidoctor-pdf -b pdf section1.adoc), it includes the image. But If I generate the PDF for mydoc.adoc (asciidoctor-pdf -b pdf mydoc.adoc) from the root, it does not include the image.

And I get the following error :

    asciidoctor: WARNING: image to embed not found or not readable: C:/myproject/images/myimg.png

I looks like as if the generation does not take care of the paths and the structure...

Can someone help me ?

Th.

Reply | Threaded
Open this post in threaded view
|

Re: Cannot include image from sub-sections

Jeremie Bresson
Image path and includes are tricky.

You can find threads I have started on similar topics:
* asciidoctor-maven-plugin and images
* Understanding include directive and file path

Now my problem are solved, I you are interested it is in a public repo. But I am using Maven and Asciidoctorj, so your use case might be different. At the end my solution was not to use imagesdir at all (set to emtpy value) and I am using my own variable "imgsdir", set to an absolute path using maven.
 
Have you the latest version of asciidoctor?

I think the image path is computed depending if you have specified an absolute or a relative path.
The {imagedir} also plays a role. There are a lot of inputs in the user manual (search for imagesdir).

"C:/myproject" is where you run the command?
It looks like that the imagesdir value is not considered at all... The default "./images" is used.

Can you print the "imagesdir" value in your text?
Just do: My image dir path is {imagesdir}

I guess you do not have a problem if your structure is flat (mydoc.adoc and chap1.adoc and section1.adoc in the same folder).

There was a bug with path starting with "../" (this was for links, but who knows). Maybe you can try "fake/../../../img" with an empty imagesdir value.

An other test you can do is to try an absolute path. According to the doc, in that case the imagesdir value should be ignored.

Reply | Threaded
Open this post in threaded view
|

Re: Cannot include image from sub-sections

thierryler
OK thx for this answer.

Based on what I understood, here is how I solded it :

In mydoc.adocs :

  :localdir: ./

In chap1.adoc :

  ifdef::localdir[]
    :localdir: chap1/
  endif::localdir[]

  ifndef::localdir[]
    :localdir: ./
  endif::localdir[]

  :imagesdir: {localdir}images

  ...

  local dir = {localdir}

  img dir = {imagesdir}

  image::somepic.jpg[]


It works :-) But I do not like to have that ifdef at the begining...