Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class FlatPlanUploader < CommonUploader
- include CarrierWave::MiniMagick
- process :convert_to_png
- def convert_to_png
- manipulate! do |image|
- inlined = "#{image.path}-inlined.svg"
- system "bin/yarn svgo -o #{inlined} --config=config/svgo.config.json #{image.path}"
- xml = Nokogiri::XML(File.read(inlined))
- xml.document.root[:style] = 'background-color: #fff'
- File.write(inlined, xml.to_xml)
- result = inlined.gsub('svg', 'png')
- system "bin/yarn svg2png #{inlined} --output=#{result} --width=500 --height=500"
- MiniMagick::Image.open(result)
- end
- end
- def full_filename(for_file)
- super.chomp(File.extname(super)) + '.png'
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement