Advertisement
Guest User

Untitled

a guest
Mar 22nd, 2019
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.68 KB | None | 0 0
  1. class FlatPlanUploader < CommonUploader
  2. include CarrierWave::MiniMagick
  3.  
  4. process :convert_to_png
  5.  
  6. def convert_to_png
  7. manipulate! do |image|
  8. inlined = "#{image.path}-inlined.svg"
  9. system "bin/yarn svgo -o #{inlined} --config=config/svgo.config.json #{image.path}"
  10.  
  11. xml = Nokogiri::XML(File.read(inlined))
  12. xml.document.root[:style] = 'background-color: #fff'
  13. File.write(inlined, xml.to_xml)
  14.  
  15. result = inlined.gsub('svg', 'png')
  16. system "bin/yarn svg2png #{inlined} --output=#{result} --width=500 --height=500"
  17. MiniMagick::Image.open(result)
  18. end
  19. end
  20.  
  21. def full_filename(for_file)
  22. super.chomp(File.extname(super)) + '.png'
  23. end
  24. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement