upbit / pixivpy

Pixiv API for Python
https://pypi.org/project/PixivPy3/#files
The Unlicense
1.79k stars 149 forks source link

Add a way to get a post's image as a bytes-like object #146

Closed ghost closed 3 years ago

ghost commented 3 years ago

Currently you can download a file with api.download(), but i only need to get the file's data to do a bit of post processing, so saving and loading the image is a long step that could be avoided Could you add a function to get a post's image that returned the image data directly?

upbit commented 3 years ago

What data do you need for the illust?

If you want the length and width, you need to query from the search_illust/user_illusts. The download interface can only get the picture size.

ghost commented 3 years ago

I need the actual image data, so what you can currently get by doing this: api.download("https://i.pximg.net/img-original/img/2020/11/06/02/20/38/85488052_p0.jpg", path=path, name="image.jpg") imagedata = open(f"{path}/image.jpg", 'rb')

This is a pretty ineffective method since it requires saving a file to the hard drive just to open it again, so a direct way to do this would be better, maybe something like imagedata = api.get_file("https://i.pximg.net/img-original/img/2020/11/06/02/20/38/85488052_p0.jpg")

Xdynix commented 3 years ago

Check this example

https://github.com/upbit/pixivpy/blob/b90d95f38a157d2d9467cbbdffd385de1afd2d39/download_illusts.py#L53

You can pass a file-like object to the fname argument of download(). It's name is a little confusing but it works.

ghost commented 3 years ago

ohhhhhh, thanks a lot!