-
Notifications
You must be signed in to change notification settings - Fork 253
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
Add support for conversion from python bytes #79
Conversation
cmdapp/vtracer/vtracer.pyi
Outdated
@@ -15,3 +15,20 @@ def convert_image_to_svg_py(image_path: str, | |||
path_precision: Optional[int] = None, # default: 8 | |||
) -> None: | |||
... | |||
|
|||
def convert_py( | |||
img_bytes: bytes, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this indentation looks too deep haha. may be you are aligning with above?
cmdapp/src/python.rs
Outdated
img_bytes: Vec<u8>, | ||
img_format: Option<&str>, // Format of the image. If not provided, the image format will be guessed based on its contents. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what are the possible image format? e.g. rgba8888
?
can you give some examples?
also, I'd say name it convert_raw_image_to_svg
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These are image file formats supported by the image
crate, listed here
Then may be I misunderstood your intention. I thought you're trying with raw image pixels. But what's the use for being able to pass in raw, undecoded image as bytes? |
It allows python users to use the library without interacting with the file system. For instance, I was using this library on a backend server that receives raster images from an external source and serve the SVG string in the response body. Before this change I have to store the raster image in the fs, call There's this discussion that called for this feature, so I thought it would be helpful to implement it. |
9f1c2c2
to
725adf5
Compare
Sorry I think I misunderstood your question. The primary reason for passing in raw bytes instead of pixels is to provide a more streightforward interface for the Python users, as in they don't have to do image loading and mode conversion on their side. from vtracer import convert_raw_image_to_svg
svg = convert_raw_image_to_svg(img_bytes, 'png') Instead of: from vtracer import convert_raw_image_to_svg
from PIL import Image
img = Image(io.BytesIO(img_bytes))
img = img.convert('RGBA')
svg = convert_raw_image_to_svg(list(img.getdata())) As we already have an image processing library on the Rust side, it feels unnecessary to require PIL for Python users imho. I could be wrong and please let me know if you want the function to accept pixels instead. |
I'd say your |
Done, please check it out |
Nice, can you also update the readme? I assume this the correct usage right? from vtracer import convert_pixels_to_svg
from PIL import Image
img = Image(io.BytesIO(img_bytes))
img = img.convert('RGBA')
svg = convert_pixels_to_svg(list(img.getdata())) And |
Yes that is correct, I have added use cases for the two functions in |
Thank you, let me try this out. |
Released! https://pypi.org/project/vtracer/0.6.11/ hey @wlyh514 I wonder what's your use case with VTracer? if it's something interesting could you share a bit |
I was building a game where some game items are dynamically generated, I employed vtracer in the (item name) => (item game icon svg) pipeline. It worked amazingly well and I'm really impressed! Thank you for building this library :) |
thanks for sharing. yeah love it, game dev is always fun. I didnt get to do it ever since I graduated |
This PR changes only the python binding of the library.
A new python function
convert_py
is exposed to allow conversion from image bytes into a SVG string, without needing to interact with the file system. Doing so addresses discussion #73 .This is not a breaking change, it did not change behaviour of already exposed functions.
There are no dependency changes involved.