Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

images displayed at the end of file #20

Open
calnfynn opened this issue Jul 8, 2024 · 2 comments
Open

images displayed at the end of file #20

calnfynn opened this issue Jul 8, 2024 · 2 comments
Assignees
Labels

Comments

@calnfynn
Copy link
Collaborator

calnfynn commented Jul 8, 2024

possibly caused by PIL. markdown syntax might be better

@calnfynn calnfynn self-assigned this Jul 8, 2024
@calnfynn
Copy link
Collaborator Author

calnfynn commented Jul 8, 2024

The PIL library the code uses works for displaying images in Jupyter Notebook, but I think Quarto doesn't understand that it is dealing with images if they're in that format. Without that information it can't convert them like it should and puts them at the very end of the PDF without doing anything to them.

The simplest solution is to put the images into Markdown format instead so that Quarto recognises them correctly:

def get_img(partOfItem_id):

    q = ""
    if partOfItem_id:
        q = query_img.replace("<placeholder>", "?partOfStatement cpsps:P6 cps:"+partOfItem_id+".")
    else:
        q = query_img.replace("<placeholder>","")

    results_img = run_query(endpoint_url, q)

    for item in results_img["results"]["bindings"]:    

        title = item['itemLabel']['value']
        description = html.unescape(item['itemDescr']['value'])

        print('\nWikibase link: ' + '[' + item['imgItem']['value'] + ']' + '(' + item['imgItem']['value'] + ')' + '\n')
        print('Title: ' + title + '\n')
        print('Year: ' + item['publishDate']['value'] + '\n')
        print('Description: ' + description + '\n')

        # get image from image URL
        image_url=item['imgUrl']['value']

        # display image with title + alt text (in markdown)
        print('!['+ title +']('+image_url+'){fig-alt="'+description+'"}\n\n')
	  

The above snippet replaces the get_img part in section.yml . This changes the image format to Markdown and also allows the Title from Wikibase to be used as the caption in the PDF, and the Description as the alt text.

Since this doesn't use the PIL library anymore, this:

from PIL import Image
from datetime import datetime
import time

and the fetch_image_by_url & get_delay functions can be deleted from the file.

@mrchristian
Copy link

mrchristian commented Jul 15, 2024

FYI - checking on local rendering and PDF image rendering at end of doc - I now find an inconsistency with images now working in PDF. We will still carry out our fix as we want to be sure things work. The repo is https://github.com/TIBHannover/section-demo - This is just to log the observation - #23

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants