Module: FFakerTW::Image
Constant Summary collapse
- SUPPORTED_FORMATS =
%w[png jpg jpeg gif].freeze
Instance Method Summary collapse
- #file(size = '300x300', format = 'png', bg_color = :random, text_color = :random, text = nil) ⇒ Object
- #url(size = '300x300', format = 'png', bg_color = :random, text_color = :random, text = nil) ⇒ Object
Methods included from ModuleUtils
const_missing, k, luhn_check, underscore, unique
Methods included from RandomUtils
#fetch_sample, #rand, #shuffle
Instance Method Details
#file(size = '300x300', format = 'png', bg_color = :random, text_color = :random, text = nil) ⇒ Object
25 26 27 28 29 30 31 32 |
# File 'lib/ffakerTW/image.rb', line 25 def file(size = '300x300', format = 'png', bg_color = :random, text_color = :random, text = nil) uri = URI.parse(url(size, format, bg_color, text_color, text)) file = Tempfile.new('ffaker_image') file.binmode file << uri.open.read file.close File.new(file.path) end |
#url(size = '300x300', format = 'png', bg_color = :random, text_color = :random, text = nil) ⇒ Object
14 15 16 17 18 19 20 21 22 23 |
# File 'lib/ffakerTW/image.rb', line 14 def url(size = '300x300', format = 'png', bg_color = :random, text_color = :random, text = nil) check_size!(size) check_format!(format) bg_color = FFakerTW::Color.hex_code if bg_color == :random text_color = FFakerTW::Color.hex_code if text_color == :random text = CGI.escape(text.to_s) "https://dummyimage.com/#{size}/#{bg_color}/#{text_color}.#{format}?text=#{text}" end |