go-shiori / go-epub

Go library for creating EPUB files
MIT License
44 stars 7 forks source link

is it possible to write []byte as a cover image? #34

Closed MarsSwimmer closed 6 months ago

MarsSwimmer commented 6 months ago

hi,

is it possible to write []byte as a cover image?

in my process it get image from network, and i dont want to store on disk, just on ram, after use to epub, the image will recycle.

Monirzadeh commented 6 months ago

you can directly pass URL to the go-epub bellow is an example of that

        // save image inside epub directly from the network
    coverPath, err := e.AddImage("https://mywebsite.com/image.jpg", "cover.jpg")
    if err != nil {
        log.Println(err)
    }

        // use that image as cover
    err = e.SetCover(coverPath, "")
    if err != nil {
        log.Println(err)
    }

more details here

MarsSwimmer commented 6 months ago

Thanks for reply,

oh, i know this solution after reading doc,

but sometime we cant do network request, or network is unstable, if there already exist a image buffer, we can use []byte to set cover image or content image.

best regard !

Monirzadeh commented 6 months ago

if you don't have network connection or file somewhere on disk. how do you have that []byte? specific code generate that image? can you give me a code sample that generate the image buffer? i need a sample to test that in different situation.

MarsSwimmer commented 6 months ago

thanks reply,

its not the problem, infact img url need network request, if it already exist img buffer, such as []byte or io reader, its no need to get img from network or from disk.

ok, there is no need, maybe its difficult. thanks again~