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

Dictionary: Support images? #6056

Closed
mergen3107 opened this issue Apr 15, 2020 · 10 comments
Closed

Dictionary: Support images? #6056

mergen3107 opened this issue Apr 15, 2020 · 10 comments
Labels

Comments

@mergen3107
Copy link
Contributor

  • KOReader version: 2020.03.02
  • Device: Kindle PW3 (5.9.7)

Can I hope about showing pictures in dictionary queries?
They show up in the =h output as <blockquote><blockquote><rref>spire.jpg</rref></blockquote></blockquote>
For example:
Reader_2020-Apr-11_183730

I am complaining, just wanted to give you my feedback on how to make it better.
If it is not possible or too hard for the purpose, then I can just hide these references as .wav files (#6011)

@Frenzie
Copy link
Member

Frenzie commented Dec 19, 2020

Something like this should do the trick. You might have to change it to <img src="/path/to/dictionary/img/files/%1">

return function(html)
html = html:gsub('<rref[^>]*>([^<]*%.jpg)</rref>', '<img src="%1">')
return html
end

@imkaihao
Copy link

@Frenzie
I do something like this but it still doesn't work.

return function(html)
    html = html:gsub('<rref[^>]*>([^<]*%.jpg)</rref>', '<img src="/path/to/dictionary/img/files/%1" />')
    return html
end

KOReader version: 2020.12
I have tested on Kobo Forma and desktop Ubuntu.
It just shows like this:
FileManager

@Frenzie
Copy link
Member

Frenzie commented Dec 26, 2020

@imkaihao That's what MuPDF puts in there when it can't find the referenced image file. Which is a virtual certainty if you kept /path/to/dictionary/img/files! ;-)

@imkaihao
Copy link

@Frenzie I mean the real path to images. In Kobo Forma it's like this

return function(html)
    html = html:gsub('<rref[^>]*>([^<]*%.jpg)</rref>', '<img src="/mnt/onboard/.adds/koreader/data/dict/stardict-Longman_Dictionary_of_Contemporary_English_5th_Ed-2.4.2/res/%1" />')
    return html
end

It doesn't work. Just showing the result like the above screenshot.

Frenzie added a commit to Frenzie/koreader that referenced this issue Dec 26, 2020
That way images can be made to work in a more generic, portable manner, such as:

```
return function(html, dict_path)
    html = html:gsub('<rref[^>]*>([^<]*%.jpg)</rref>', '<img src="'..dict_path..'res/%1">')
    return html
end
```

Cf. <koreader#6056>.
@Frenzie
Copy link
Member

Frenzie commented Dec 26, 2020

If you use data/dict/etc. it should work.

@imkaihao
Copy link

@Frenzie
Thank you. It works now. And with the new pull request, I don't need to write the path for each dictionary.

Frenzie added a commit that referenced this issue Dec 26, 2020
That way images can be made to work in a more generic, portable manner, such as:

```
return function(html, dict_path)
    html = html:gsub('<rref[^>]*>([^<]*%.jpg)</rref>', '<img src="'..dict_path..'res/%1">')
    return html
end
```

Cf. <#6056>.
@ptrm
Copy link
Contributor

ptrm commented Dec 27, 2020

Should png work as well? I had tried to make this work years ago ending up with [image] each time, and now tried again thinking maybe I had got the paths wrong before. But most I can get still is [image]:
20201227_142501
(That's on Android 10 on Onyx Boox Nova 3, both Termux and KOReader have generic storage access)

@Frenzie
Copy link
Member

Frenzie commented Dec 27, 2020

Should png work as well?

In fact, probably just about any image format you can throw at it except for WebP. (E.g., JPEG2000 isn't commonly supported but MuPDF does.)

But as established above there's something slightly odd going on with full absolute paths. Sticking a file:// in front of it doesn't work either. I didn't want to spend time investigating since using relative paths worked, but that might mean it won't work on Android for the moment. Also I'm trying to avoid looking at MuPDF until #6738 is merged.

As an aside, even if it's still an issue in 1.17/1.18, it'll support base64-encoded images which you always could use as a workaround.

@ptrm
Copy link
Contributor

ptrm commented Dec 27, 2020

Also I'm trying to avoid looking at MuPDF until #6738 is merged.

I see. I'll just live the relative path and shorter dirname attempt and wait a bit:
20201227_153142
20201227_153755
(the /…com.termux…storage/shared part is just a symlink to proper /storage/emulated/0/)

As an aside, even if it's still an issue in 1.17/1.18, it'll support base64-encoded images which you always could use as a workaround.

🔥🎉

@ptrm
Copy link
Contributor

ptrm commented Dec 27, 2020

BUT doing the good old relative-path-up-dir exploit works \o/
20201227_160917

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

4 participants