Register Guidelines E-Books Today's Posts Search

Go Back   MobileRead Forums > E-Book Readers > Kobo Reader > Kobo Developer's Corner

Notices

Reply
 
Thread Tools Search this Thread
Old 04-01-2024, 06:54 AM   #1
gonzule
before sleep, read or TV?
gonzule began at the beginning.
 
Posts: 104
Karma: 10
Join Date: Apr 2008
Location: Australia
Device: Kobo Libra 2
Workarounds to displaying an SVG image?

Hi, I'm trying to display an SVG image using FBink but its not part of the features. I'm looking for a workaround to it but haven't been able to find anything that works by running python on my Kobo Aura. Any ideas of an already existing workaround to get this working in fbink?

I was thinking maybe converting the SVG to another format, but after trying a few recommendations i found online (e.g. cairo) they don't seem to work well on my kobo (while installing some, the reader would crash, or i would get an error that there isn't enough storage while downloading the necessary packages/libraries)
gonzule is offline   Reply With Quote
Old 04-01-2024, 01:38 PM   #2
DNSB
Bibliophagist
DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.
 
DNSB's Avatar
 
Posts: 35,755
Karma: 145624992
Join Date: Jul 2010
Location: Vancouver
Device: Kobo Sage, Forma, Clara HD, Lenovo M8 FHD, Paperwhite 4, Tolino epos
If they are fixed images, can you convert them before sending to your Kobo? Assuming you are not downloading the images directly to your Kobo.
DNSB is online now   Reply With Quote
Old 04-01-2024, 06:46 PM   #3
gonzule
before sleep, read or TV?
gonzule began at the beginning.
 
Posts: 104
Karma: 10
Join Date: Apr 2008
Location: Australia
Device: Kobo Libra 2
ah, forgot to mention that I am generating these inside my Kobo through a python script. I'm using a script that collects weather data and replaces some text on a preexisting SVG image with the weather info, but them i am struggling to display this on my kobo.
gonzule is offline   Reply With Quote
Old 04-02-2024, 09:33 AM   #4
Szybet
Connoisseur
Szybet can teach chickens to fly.Szybet can teach chickens to fly.Szybet can teach chickens to fly.Szybet can teach chickens to fly.Szybet can teach chickens to fly.Szybet can teach chickens to fly.Szybet can teach chickens to fly.Szybet can teach chickens to fly.Szybet can teach chickens to fly.Szybet can teach chickens to fly.Szybet can teach chickens to fly.
 
Posts: 88
Karma: 3892
Join Date: Feb 2022
Device: Kobo nia
python can't convert images via a simple library? rust can do that, even chatgpt will tell you such a program then simply compile it using cross
Szybet is offline   Reply With Quote
Old 04-03-2024, 05:16 PM   #5
geek1011
Wizard
geek1011 ought to be getting tired of karma fortunes by now.geek1011 ought to be getting tired of karma fortunes by now.geek1011 ought to be getting tired of karma fortunes by now.geek1011 ought to be getting tired of karma fortunes by now.geek1011 ought to be getting tired of karma fortunes by now.geek1011 ought to be getting tired of karma fortunes by now.geek1011 ought to be getting tired of karma fortunes by now.geek1011 ought to be getting tired of karma fortunes by now.geek1011 ought to be getting tired of karma fortunes by now.geek1011 ought to be getting tired of karma fortunes by now.geek1011 ought to be getting tired of karma fortunes by now.
 
Posts: 2,749
Karma: 6990705
Join Date: May 2016
Location: Ontario, Canada
Device: Kobo Mini, Aura Edition 2 v1, Clara HD
Quote:
Originally Posted by gonzule View Post
I was thinking maybe converting the SVG to another format, but after trying a few recommendations i found online (e.g. cairo) they don't seem to work well on my kobo (while installing some, the reader would crash, or i would get an error that there isn't enough storage while downloading the necessary packages/libraries)
How exactly are you trying to install them? I'd recommend just compiling them yourself.

Alternatively, with a bit of code, it should be possible to make some nice bindings between FBInk and resvg.
geek1011 is online now   Reply With Quote
Old 04-03-2024, 07:04 PM   #6
sublipri
Member
sublipri can self-interpret dreams as they happen.sublipri can self-interpret dreams as they happen.sublipri can self-interpret dreams as they happen.sublipri can self-interpret dreams as they happen.sublipri can self-interpret dreams as they happen.sublipri can self-interpret dreams as they happen.sublipri can self-interpret dreams as they happen.sublipri can self-interpret dreams as they happen.sublipri can self-interpret dreams as they happen.sublipri can self-interpret dreams as they happen.sublipri can self-interpret dreams as they happen.
 
Posts: 24
Karma: 20342
Join Date: Jul 2023
Device: Kobo Glo, Kobo Sage
Quote:
Originally Posted by geek1011 View Post
Alternatively, with a bit of code, it should be possible to make some nice bindings between FBInk and resvg.
I had a quick try at using resvg with the bindings I've been working on. Got a basic SVG to print but haven't figured out how to scale it to the screen size yet, and might need to deal with transparency too.

Spoiler:
Code:
use fbink_rs::FbInk;
use resvg::tiny_skia;
use resvg::usvg::{self, fontdb, Size};

fn main() {
    let svg_data = include_bytes!("../test.svg");
    let fbink = FbInk::new(Default::default()).unwrap();
    let state = fbink.state();
    let width = state.view_width;
    let height = state.view_height;
    let size = Size::from_wh(width as f32, height as f32).unwrap();

    let tree = {
        let opt = usvg::Options {
            default_size: size,
            dpi: 300.0,
            ..Default::default()
        };
        let mut fontdb = fontdb::Database::new();
        let font = include_bytes!("../DejaVuSans.ttf");
        fontdb.load_font_data(font.to_vec());
        usvg::Tree::from_data(svg_data, &opt, &fontdb).unwrap()
    };
    let mut pixmap = tiny_skia::Pixmap::new(width, height).unwrap();
    resvg::render(&tree, Default::default(), &mut pixmap.as_mut());
    fbink
        .print_raw_data(pixmap.data(), width as i32, height as i32, 0, 0)
        .unwrap();
}


Quote:
Originally Posted by gonzule View Post
I'm using a script that collects weather data and replaces some text on a preexisting SVG image with the weather info, but them i am struggling to display this on my kobo.
If you don't have any experience with Rust I could try creating a binary that'll display the SVG if you attach an example file that's been processed by your Python script.
sublipri is offline   Reply With Quote
Old 04-03-2024, 08:40 PM   #7
gonzule
before sleep, read or TV?
gonzule began at the beginning.
 
Posts: 104
Karma: 10
Join Date: Apr 2008
Location: Australia
Device: Kobo Libra 2
Quote:
Originally Posted by sublipri View Post
If you don't have any experience with Rust I could try creating a binary that'll display the SVG if you attach an example file that's been processed by your Python script.
Thanks. My experience is VERY limited, so I'm just googling and ChatGPT-ing everything, using some basic coding knowledge i have from years ago.

Attached is an example SVG I'm getting as output. As mentioned, easiest thing would be to be able to get FBink to display it as is, or t convert it to png or another format supported by FBink.

I have been able to create this SVG both on my computer, and by running a Python script on my Kobo Aura. This is the source script
https://github.com/mattzzw/kindle-we...weather2svg.py
Attached Files
File Type: zip weather-script-output.zip (69.6 KB, 43 views)
gonzule is offline   Reply With Quote
Old 04-03-2024, 11:34 PM   #8
sublipri
Member
sublipri can self-interpret dreams as they happen.sublipri can self-interpret dreams as they happen.sublipri can self-interpret dreams as they happen.sublipri can self-interpret dreams as they happen.sublipri can self-interpret dreams as they happen.sublipri can self-interpret dreams as they happen.sublipri can self-interpret dreams as they happen.sublipri can self-interpret dreams as they happen.sublipri can self-interpret dreams as they happen.sublipri can self-interpret dreams as they happen.sublipri can self-interpret dreams as they happen.
 
Posts: 24
Karma: 20342
Join Date: Jul 2023
Device: Kobo Glo, Kobo Sage
Quote:
Originally Posted by gonzule View Post
Attached is an example SVG I'm getting as output. As mentioned, easiest thing would be to be able to get FBink to display it as is, or t convert it to png or another format supported by FBink.
Try the binary I've attached. It works on my Glo with your example file. You'll need to provide the path to the SVG file as the first argument when you call it from the python script.
Attached Files
File Type: zip fbink-svg.zip (1.73 MB, 49 views)
sublipri is offline   Reply With Quote
Old 04-04-2024, 09:28 AM   #9
gonzule
before sleep, read or TV?
gonzule began at the beginning.
 
Posts: 104
Karma: 10
Join Date: Apr 2008
Location: Australia
Device: Kobo Libra 2
Thanks for this. Will test it over the weekend and report back!
gonzule is offline   Reply With Quote
Old 04-21-2024, 02:52 AM   #10
gonzule
before sleep, read or TV?
gonzule began at the beginning.
 
Posts: 104
Karma: 10
Join Date: Apr 2008
Location: Australia
Device: Kobo Libra 2
Quote:
Originally Posted by sublipri View Post
Try the binary I've attached. It works on my Glo with your example file. You'll need to provide the path to the SVG file as the first argument when you call it from the python script.
Hi, i finally managed some time to test this, after struggling with a lot of personal things!it works perfectly, and i was able to properly display the SVG after it was created by the script, so thank you so much!

Quick question re your binary. Does it support other fbink commands/options? I tried displaying the image using some parameters that work for mewith fbink, but they don't seemt to be recognised here:

fbink -c -f -i weather-script-output.png -g w=-1,h=-1 works ok, but neither of these other 2 seem to work

fbink-svg -c -f -i weather-script-output.svg -g w=-1,h=-1
or
fbink-svg weather-script-output.svg -c -f -i -g w=-1,h=-1

I need those extra parameters to force a complete refresh of the screen. I haveone of those screens that are VERY prone to ghosting effects, so I need a full refresh to be able toproperly see the image.

The workaround i'm using now is displaying a blank png using fbink and the desired parameters, and then using your binary to display the SVG.

Last edited by gonzule; 04-21-2024 at 06:44 AM.
gonzule is offline   Reply With Quote
Old 04-22-2024, 09:45 PM   #11
sublipri
Member
sublipri can self-interpret dreams as they happen.sublipri can self-interpret dreams as they happen.sublipri can self-interpret dreams as they happen.sublipri can self-interpret dreams as they happen.sublipri can self-interpret dreams as they happen.sublipri can self-interpret dreams as they happen.sublipri can self-interpret dreams as they happen.sublipri can self-interpret dreams as they happen.sublipri can self-interpret dreams as they happen.sublipri can self-interpret dreams as they happen.sublipri can self-interpret dreams as they happen.
 
Posts: 24
Karma: 20342
Join Date: Jul 2023
Device: Kobo Glo, Kobo Sage
Quote:
Originally Posted by gonzule View Post
i was able to properly display the SVG after it was created by the script, so thank you so much!
No problem!

Quote:
Quick question re your binary. Does it support other fbink commands/options? I tried displaying the image using some parameters that work for mewith fbink, but they don't seemt to be recognised here:
The binary doesn't support any of the commands/options from the fbink CLI. It's just a simple utility that's hard-coded to print an SVG with the same properties as your example file. I've modified it to do a flashing clear in (I think) the same way your fbink command does, so hopefully this new version won't require a workaround. Also changed it so that if given a directory as a second argument it will load any font files from there instead of using a hard-coded font, which might make it usable with different SVGs. So you should either use it as:

fbink-svg weather-script-output.svg

or

fbink-svg weather-script-output.svg /path/to/fonts

Here's the code, FWIW:

Spoiler:
Code:
use std::{env, fs};

use fbink_rs::{FbInk, FbInkConfig};
use resvg::tiny_skia;
use resvg::usvg::{self, fontdb};

fn main() {
    let Some(svg_path) = env::args_os().nth(1) else {
        println!("Usage: ./fbink-svg SVG_FILE FONT_DIR");
        return;
    };
    let svg_data = fs::read(svg_path).expect("Failed to read SVG file");
    let config = FbInkConfig {
        is_flashing: true,
        is_cleared: true,
        ..Default::default()
    };
    let fbink = FbInk::new(config).expect("Failed to initialize FBInk");
    let state = fbink.state();
    let width = state.view_width;
    let height = state.view_height;

    let tree = {
        let mut fontdb = fontdb::Database::new();
        let default_font = include_bytes!("../default.ttf");
        if let Some(font_dir) = env::args_os().nth(2) {
            fontdb.load_fonts_dir(font_dir);
        } else {
            fontdb.load_font_data(default_font.to_vec());
        }
        usvg::Tree::from_data(&svg_data, &Default::default(), &fontdb)
            .expect("Failed to create SVG tree")
    };
    let mut pixmap = tiny_skia::Pixmap::new(width, height).expect("Failed to render SVG");
    resvg::render(&tree, Default::default(), &mut pixmap.as_mut());
    fbink
        .print_raw_data(pixmap.data(), width as i32, height as i32, 0, 0)
        .expect("Failed to print SVG to screen");
}
Attached Files
File Type: zip fbink-svg.zip (1.73 MB, 28 views)
sublipri is offline   Reply With Quote
Old 04-26-2024, 08:15 PM   #12
gonzule
before sleep, read or TV?
gonzule began at the beginning.
 
Posts: 104
Karma: 10
Join Date: Apr 2008
Location: Australia
Device: Kobo Libra 2
Thanks again! This worked like a charm! I'll work now using kfmon to launch the script to generate the svg and then displaying it using your binary and should be all set! Thank you for taking the time to coding this
gonzule is offline   Reply With Quote
Reply


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Displaying SVG jiembe Editor 4 05-14-2021 07:43 AM
svg image on top of a background png image roger64 ePub 25 04-24-2015 11:00 AM
Display of a png image linked to a svg image roger64 Editor 6 03-13-2015 06:21 AM
SVG Images on iPad - contained bitmap image not displaying heulwen.jones ePub 5 04-07-2014 12:42 AM
Help displaying SVG notes. mastroalex Sony Reader Dev Corner 2 09-30-2011 05:16 AM


All times are GMT -4. The time now is 07:55 PM.


MobileRead.com is a privately owned, operated and funded community.