Class: DefaultAvatarGenerator::ImageConverter
- Inherits:
-
Object
- Object
- DefaultAvatarGenerator::ImageConverter
- Defined in:
- lib/default_avatar_generator/image_converter.rb
Overview
Converts SVG to other image formats
Class Method Summary collapse
Class Method Details
.svg_to_jpeg(svg_content) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/default_avatar_generator/image_converter.rb', line 8 def self.svg_to_jpeg(svg_content) # Create a temporary file to store the SVG temp_svg = Tempfile.new(['avatar', '.svg']) begin temp_svg.write(svg_content) temp_svg.close # Load the SVG using vips and convert to JPEG image = Vips::Image.new_from_file(temp_svg.path) # Convert to sRGB color space and save as JPEG to memory image = image.colourspace('srgb') image.jpegsave_buffer(Q: 90) ensure # Clean up temporary file temp_svg.unlink end end |