svg2img 0.2.3 → 0.2.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8d6841dd1aea05aa5ed5827d948ca86cf1e36d17e984ceb80a599aec782c1f15
4
- data.tar.gz: 3378c9fc7c35f206fa0fe2b09a17dbc9c3418b32209bbeb4fbbbf303b6c167c3
3
+ metadata.gz: 73a2ea65b81532ded264b2ec92e94d3ac146fda59529c2501625e1ac0fa6472c
4
+ data.tar.gz: 1a378f708361feec86a69733148206d175cb58b354f4f140ab7f2e5fa10faf9d
5
5
  SHA512:
6
- metadata.gz: 2504c062ea1b85efe8a4d2f6dcfa4689e75ad82734ceb575b82472bc6313397d4c0869d6658a6ac28f6198ca42fbb4d5a55138d504c31575197ce8fdf7a92838
7
- data.tar.gz: 353861ba80c505ea21b6fab8d269bd46ce9807297b6ef96f2a332cf0b7c8a268bba2985aa2116cff5afce6be4e0f7043724babad45646ec24248400d1e582a2b
6
+ metadata.gz: e0ae235c6a4addf8c2495bd2674f1508359ec58d08d77d1944587cab178dee8a32657f5b6c77c68a1a541a4a7b01889d9eae8980b18cd1dd96235bd1f8d55899
7
+ data.tar.gz: b7af313204aaac5b70b08b614cacced3eb56d35c54febbb4da93c316842f724236729ab41b12575779284e60e36cacf7dc17df02bca4269b1f002f6ef76f5f81
data/Cargo.toml CHANGED
@@ -7,6 +7,5 @@ members = ["./ext/svg2img"]
7
7
  resolver = "2"
8
8
 
9
9
  [profile.release]
10
- codegen-units = 1
11
10
  lto = true
12
11
  strip = true
@@ -1,5 +1,5 @@
1
1
  use anyhow::Context;
2
- use image::{DynamicImage, ImageBuffer};
2
+ use image::{DynamicImage, ImageBuffer, ImageEncoder};
3
3
  use magnus::{block::Proc, function, prelude::*, Error, Ruby};
4
4
  use std::panic::{self, AssertUnwindSafe};
5
5
 
@@ -127,9 +127,27 @@ fn process_svg(svg: String, options: Options) -> Result<String, anyhow::Error> {
127
127
 
128
128
  let mut buf = Vec::new();
129
129
  let mut cursor = std::io::Cursor::new(&mut buf);
130
- image
131
- .write_to(&mut cursor, options.format)
132
- .context("Failed to write image to buffer")?;
130
+ match options.format {
131
+ image::ImageFormat::Png => {
132
+ image::codecs::png::PngEncoder::new_with_quality(
133
+ &mut cursor,
134
+ image::codecs::png::CompressionType::Best,
135
+ image::codecs::png::FilterType::Adaptive,
136
+ )
137
+ .write_image(
138
+ &image.to_rgba8().into_raw(),
139
+ image.width(),
140
+ image.height(),
141
+ image.color().into(),
142
+ )
143
+ .context("Failed to encode PNG")?;
144
+ }
145
+ _ => {
146
+ image
147
+ .write_to(&mut cursor, options.format)
148
+ .context("Failed to write image to buffer")?;
149
+ }
150
+ };
133
151
 
134
152
  let output_path = options.output_path.unwrap_or_else(|| {
135
153
  let random_filename = format!(
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Svg2Img
4
- VERSION = "0.2.3"
4
+ VERSION = "0.2.4"
5
5
  end
@@ -7,6 +7,5 @@ members = ["./ext/svg2img"]
7
7
  resolver = "2"
8
8
 
9
9
  [profile.release]
10
- codegen-units = 1
11
10
  lto = true
12
11
  strip = true