class Kanoko::Application::Convert

Constants

EXT_MAP
IMAGE_TYPES
QUERY_REGEXP
TYPE_MAP

Private Instance Methods

after_response(res) click to toggle source
# File lib/kanoko/application/convert.rb, line 182
def after_response(res)
  res.each do |key, value|
    case key.downcase
    when "status"
      next
    else
      headers[key] ||= value
    end
  end
end
http_get(uri, headers) click to toggle source
# File lib/kanoko/application/convert.rb, line 151
def http_get(uri, headers)
  retries = 2
  req = Net::HTTP::Get.new(uri.request_uri)
  headers.each do |key, value|
    case key
    when "HTTP_HOST"
      next
    end
    k = key.sub(/^HTTP_/, '')
    req[k] = value if !req[k]
  end
  http = Net::HTTP.new(uri.host, uri.port)
  http.read_timeout = 1
  http.use_ssl = true if uri.scheme == 'https'
  begin
    res = http.start do |http|
      http.request(req)
    end
    res.value
    res
  rescue => e
    if 1 < retries
      retries -= 1
      sleep rand(0..0.3)
      retry
    end
    logger.error "Can not get image from '#{uri}' with #{e.message}"
    nil
  end
end
system_command(options, src_path, dst_path) click to toggle source
# File lib/kanoko/application/convert.rb, line 139
def system_command(options, src_path, dst_path)
  [
    { "OMP_NUM_THREADS" => "1" },
    'convert',
    '-depth', '8',
    '-background', 'none',
    options,
    src_path,
    dst_path,
  ].flatten
end