Module: FFaker::Image

Extended by:
Image, ModuleUtils
Included in:
Image
Defined in:
lib/ffaker/image.rb

Constant Summary collapse

SUPPORTED_FORMATS =
%w[png jpg jpeg gif].freeze

Instance Method Summary collapse

Methods included from ModuleUtils

const_missing, k, 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


24
25
26
# File 'lib/ffaker/image.rb', line 24

def file(size = '300x300', format = 'png', bg_color = :random, text_color = :random, text = nil)
  download_file(url(size, format, bg_color, text_color, text))
end

#url(size = '300x300', format = 'png', bg_color = :random, text_color = :random, text = nil) ⇒ Object


13
14
15
16
17
18
19
20
21
22
# File 'lib/ffaker/image.rb', line 13

def url(size = '300x300', format = 'png', bg_color = :random, text_color = :random, text = nil)
  check_size!(size)
  check_format!(format)

  bg_color = FFaker::Color.hex_code if bg_color == :random
  text_color = FFaker::Color.hex_code if text_color == :random
  text = CGI.escape(text.to_s)

  "https://via.placeholder.com/#{size}/#{bg_color}/#{text_color}.#{format}?text=#{text}"
end