default-avatar-generator 0.2.2 → 0.2.3

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: dfbf2f6413aea2b6d8f7e16a23724a58b3a6b80aaeabc1c223028a46c8d774d0
4
- data.tar.gz: ce5156d52dba3d8786ab92e17446096b4ef7ff6d227892786eebac982e8d5541
3
+ metadata.gz: e3165c7270d8573beca2c669dd7850f14f3dab8f34b26602f4bc062cb7037c0e
4
+ data.tar.gz: ce6ec90e9e842edd3d1fdcd07041edcc511a3b68595d2bd2b74cd94502aa5150
5
5
  SHA512:
6
- metadata.gz: 91baf2b7ea5c12b817c3a7f1454e3951cb62f23d705ce28892f23b51e64e7bb2be7d99374c7600a5153a5180693fef198f4a9f9160227ce0f96f26640551e186
7
- data.tar.gz: 6b502f605e900d4791762bc14d61b1108c875f2b4afaeed223ba7de942098c120d8e1f09d3dfb51ddd6a57f4d55c3eb6a3ae22678a7f76cb7b26f31122e4a764
6
+ metadata.gz: 8d29bdfbbde705eb1f5000ab6e92e1a3311205cd852a53931e0cac6702bc8f434fdf51a212a17daaeb45bcecbf7ba8a24115b39e5edb9d6cce18fc67fa7789bf
7
+ data.tar.gz: 5cf3d7de8b547cc903c9544ffa1a76b3b5d98f1d9b994751f9d417ea815c783942548f080bf6ef0a1d16b3298e627611776460e21c6a38282ee5630c2ce0c14c
data/CHANGELOG.md CHANGED
@@ -5,6 +5,18 @@ All notable changes to this project will be documented in this file.
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
+ ## [0.2.3] - 2026-09-07
9
+
10
+ ### Fixed
11
+
12
+ - `ImageConverter.svg_to_jpeg` no longer uses vips's own SVG loader at all — it now
13
+ rasterizes via the `rsvg-convert` CLI first, then hands vips the resulting PNG.
14
+ 0.2.2's buffer-load change did not actually fix the underlying issue: apps that load
15
+ Rails Active Storage call `Vips.block_untrusted(true)` on boot, which disables vips's
16
+ `svgload` **and** `svgload_buffer` process-wide (both are flagged `untrusted`), so the
17
+ conversion still failed 100% of the time in any app using Active Storage. This adds a
18
+ new system dependency: `librsvg2-bin` (Debian/Ubuntu) / `librsvg` (Homebrew).
19
+
8
20
  ## [0.2.2] - 2026-09-07
9
21
 
10
22
  ### Fixed
data/README.md CHANGED
@@ -11,6 +11,10 @@ A Ruby gem that generates beautiful default avatars for user accounts when no cu
11
11
 
12
12
  ## Installation
13
13
 
14
+ This gem shells out to the `rsvg-convert` CLI (from `librsvg2-bin` on Debian/Ubuntu,
15
+ `librsvg` on Homebrew) to rasterize the generated SVG, and uses [ruby-vips](https://github.com/libvips/ruby-vips)
16
+ (which requires `libvips`) to convert that to JPEG. Both must be installed on the host.
17
+
14
18
  Add this line to your application's Gemfile:
15
19
 
16
20
  ```ruby
@@ -37,6 +41,12 @@ jpeg_avatar = DefaultAvatarGenerator::ImageConverter.svg_to_jpeg(svg_avatar)
37
41
  # Save the avatar to a file (if you need to)
38
42
  ```
39
43
 
44
+ Note: `ImageConverter.svg_to_jpeg` rasterizes via `rsvg-convert` rather than vips's own SVG
45
+ loader. Apps that load Rails Active Storage call `Vips.block_untrusted(true)` on boot, which
46
+ disables vips's `svgload`/`svgload_buffer` process-wide (they're flagged `untrusted` since they
47
+ rely on rsvg's unfuzzed parser) — that would break this gem even for the SVGs it generates
48
+ itself. Going through `rsvg-convert` avoids that entirely.
49
+
40
50
  ## Development
41
51
 
42
52
  After checking out the repo:
@@ -1,17 +1,33 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'open3'
4
+
3
5
  module DefaultAvatarGenerator
4
6
  # Converts SVG to other image formats
5
7
  class ImageConverter
6
8
  def self.svg_to_jpeg(svg_content)
7
- # Load the SVG directly from memory and convert to JPEG. Avoids round-tripping
8
- # through a temp file, which intermittently failed in production with
9
- # "is not a known file format" when the file wasn't fully flushed/visible yet.
10
- image = Vips::Image.new_from_buffer(svg_content, '')
9
+ # libvips's SVG loader is marked "untrusted" (it relies on rsvg's unfuzzed parser),
10
+ # and apps that load Active Storage disable all untrusted vips operations globally
11
+ # via Vips.block_untrusted(true) -- see https://github.com/rails/rails/pull/49236.
12
+ # That blocks svgload/svgload_buffer even for content we generated ourselves, so we
13
+ # rasterize with the rsvg-convert CLI instead, then hand vips a (trusted) PNG.
14
+ png_bytes = svg_to_png(svg_content)
11
15
 
12
- # Convert to sRGB color space and save as JPEG to memory
16
+ image = Vips::Image.new_from_buffer(png_bytes, '')
13
17
  image = image.colourspace('srgb')
14
18
  image.jpegsave_buffer(Q: 90)
15
19
  end
20
+
21
+ def self.svg_to_png(svg_content)
22
+ png_bytes, stderr, status = Open3.capture3(
23
+ 'rsvg-convert', '-f', 'png', stdin_data: svg_content, binmode: true
24
+ )
25
+ raise Error, "rsvg-convert failed: #{stderr}" unless status.success?
26
+
27
+ png_bytes
28
+ rescue Errno::ENOENT
29
+ raise Error, 'rsvg-convert executable not found. Install librsvg (e.g. librsvg2-bin on Debian/Ubuntu).'
30
+ end
31
+ private_class_method :svg_to_png
16
32
  end
17
33
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module DefaultAvatarGenerator
4
- VERSION = '0.2.2'
4
+ VERSION = '0.2.3'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: default-avatar-generator
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Peter Sankauskas