anton-sviridov / retina-cli

CLI client for Retina
0 stars 0 forks source link

[fn detect] convert an image to base64 Data URL in webp #4

Open anton-sviridov opened 2 weeks ago

anton-sviridov commented 2 weeks ago

Input: image filepath Output: base64 Data URL

Steps:

1. Get an image from path

To manipulate filesystem operations there is a module std::fs. With File::open it is possible to get std::fs::File from string.

To manipulate image operations in filesystem i will use crate image and its function image::open(), because it returns ImageResult\<DynamicImage> as we need in next step

2. Convert the image to webp

To convert image to webp I will use crate "webp":

3. Convert webp to [u8]

As input to base64_url::encode() [u8] in next step is required.

Possibly, as_bytes(&self) -> &[u8] solute this

4. Encode [u8] to Data URL

To do this step we need function base64_url::encode in crate base64_url

anton-sviridov commented 2 weeks ago

We have:

  1. string "path/to/image.img"
  2. file: DynamicImage
  3. webp in [u8]
  4. Data URL: String

In issues #7 and #9 this image file is needed, so we can implement them before step 2 image::save_buffer("image.png", buffer, 800, 600, image::ExtendedColorType::Rgb8).unwrap()

anton-sviridov commented 2 weeks ago

Test:

$ wget https://www.gstatic.com/webp/gallery/1.webp -O test.webp
$ retina-cli detect --image test.webp ...
# data:image/webp;base64,UklGRmh2AABXRUJQVlA
anton-sviridov commented 2 weeks ago

finished, test is failed now

anton-sviridov commented 2 weeks ago

future test -- compare results from retina-cli and retina-tauri

anton-sviridov commented 2 weeks ago

Test passed:

cargo install dataurl
dataurl -i miscommunication2-337x426.webp -b --media-type "image/webp"