diff --git a/Cargo.lock b/Cargo.lock index 9be4e88..864d779 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -171,15 +171,6 @@ dependencies = [ "cfg-if", ] -[[package]] -name = "matrixmultiply" -version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "add85d4dd35074e6fedc608f8c8f513a3548619a9024b751949ef0e8e45a4d84" -dependencies = [ - "rawpointer", -] - [[package]] name = "memmap2" version = "0.5.10" @@ -207,62 +198,6 @@ dependencies = [ "adler", ] -[[package]] -name = "ndarray" -version = "0.15.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "adb12d4e967ec485a5f71c6311fe28158e9d6f4bc4a447b474184d0f91a8fa32" -dependencies = [ - "matrixmultiply", - "num-complex", - "num-integer", - "num-traits", - "rawpointer", -] - -[[package]] -name = "num-complex" -version = "0.4.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "02e0d21255c828d6f128a1e41534206671e8c3ea0c62f32291e808dc82cff17d" -dependencies = [ - "num-traits", -] - -[[package]] -name = "num-integer" -version = "0.1.45" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "225d3389fb3509a24c93f5c29eb6bde2586b98d9f016636dff58d7c6f7569cd9" -dependencies = [ - "autocfg", - "num-traits", -] - -[[package]] -name = "num-traits" -version = "0.2.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "578ede34cf02f8924ab9447f50c28075b4d3e5b269972345e7e0372b38c6cdcd" -dependencies = [ - "autocfg", -] - -[[package]] -name = "numpy" -version = "0.18.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "96b0fee4571867d318651c24f4a570c3f18408cf95f16ccb576b3ce85496a46e" -dependencies = [ - "libc", - "ndarray", - "num-complex", - "num-integer", - "num-traits", - "pyo3", - "rustc-hash", -] - [[package]] name = "once_cell" version = "1.17.1" @@ -388,12 +323,6 @@ dependencies = [ "proc-macro2", ] -[[package]] -name = "rawpointer" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "60a357793950651c4ed0f3f52338f53b2f809f32d83a07f72909fa13e4c6c1e3" - [[package]] name = "rctree" version = "0.5.0" @@ -431,7 +360,6 @@ dependencies = [ name = "resvg-py" version = "0.0.1" dependencies = [ - "numpy", "pyo3", "resvg", "tiny-skia", @@ -469,12 +397,6 @@ dependencies = [ "xmlparser", ] -[[package]] -name = "rustc-hash" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2" - [[package]] name = "rustybuzz" version = "0.7.0" diff --git a/Cargo.toml b/Cargo.toml index 46df48a..5fdcdf1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,7 +9,6 @@ name = "resvg_py" crate-type = ["cdylib"] [dependencies] -numpy = "0.18.0" pyo3 = "0.18.1" resvg = "0.30.0" tiny-skia = "0.8.3" diff --git a/README.md b/README.md index f1df5b7..9c13778 100644 --- a/README.md +++ b/README.md @@ -19,17 +19,15 @@ Overall, `resvg-py` provides a simple and powerful way to work with SVG images i from pathlib import Path import resvg_py -from PIL import Image options = resvg_py.SVGOptions() r = resvg_py.Resvg(options) with Path("resources/examples/svg/octocat.svg").open("r") as f: rendered = r.render(f.read(), 400, 400) - array = rendered.as_array() - im = Image.fromarray(array) - im.save("image.png") + with open("image.png", "wb") as f: + f.write(rendered.as_png()) ``` # Options diff --git a/pyproject.toml b/pyproject.toml index c0fe6fc..aaced35 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -11,10 +11,7 @@ classifiers = [ "Programming Language :: Python :: Implementation :: CPython", "Programming Language :: Python :: Implementation :: PyPy", ] -dependencies = [ - "numpy", - "Pillow", -] +dependencies = [] [project.optional-dependencies] dev = ["pytest", "pytest-snapshot"] diff --git a/src/lib.rs b/src/lib.rs index 0018d14..c47e1f8 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,5 +1,3 @@ -use numpy::ndarray::Array3; -use numpy::{IntoPyArray, PyArray3}; use pyo3::prelude::*; use pyo3::types::PyBytes; use resvg::tiny_skia::Pixmap; @@ -128,30 +126,6 @@ impl RenderedImage { self.pixmap.height() } - /// Returns the rendered image as a numpy array. - /// - /// The array has shape (height, width, 4) and contains RGBA data. - pub fn as_array<'py>(&self, py: Python<'py>) -> PyResult<&'py PyArray3> { - let pixels = self.pixmap.pixels(); - - Ok(Array3::from_shape_fn( - ((self.height()) as usize, (self.width()) as usize, 4), - |(y, x, c)| { - let index = y * self.width() as usize + x; - let pixel = &pixels[index]; - - match c { - 0 => pixel.red(), - 1 => pixel.green(), - 2 => pixel.blue(), - 3 => pixel.alpha(), - _ => unreachable!(), - } - }, - ) - .into_pyarray(py)) - } - /// Returns the rendered image as bytes in PNG format. fn as_png(&self, py: Python) -> PyResult { self.pixmap