Ruby QR코드 라이브러리

Ruby로 QR코드 생성

Ruby의 rqrcode gem은 QR코드 생성을 간단하고 우아하게 만듭니다. Rails 애플리케이션, 스크립트, 자동화 워크플로에 적합합니다.

설치

Bundler 또는 gem install을 사용하여 rqrcode gem을 설치하세요.

Gemfile
gem 'rqrcode'
gem
gem install rqrcode

rqrcode로 QR코드 생성

Ruby에서 rqrcode gem을 사용한 코드 예제.

QR Code as SVG
require 'rqrcode'

qr = RQRCode::QRCode.new('https://qrcode.fun')

svg = qr.as_svg(
  offset: 0,
  color: '1A2B3C',
  shape_rendering: 'crispEdges',
  module_size: 6,
  standalone: true
)

File.write('qrcode.svg', svg)
QR Code as PNG
require 'rqrcode'

qr = RQRCode::QRCode.new('https://qrcode.fun')

png = qr.as_png(
  bit_depth: 1,
  border_modules: 4,
  color_mode: ChunkyPNG::COLOR_GRAYSCALE,
  color: 'black',
  file: nil,
  fill: 'white',
  module_px_size: 6,
  resize_exactly_to: false,
  resize_gte_to: false,
  size: 300
)

IO.binwrite('qrcode.png', png.to_s)
Rails Controller
class QrCodesController < ApplicationController
  def show
    qr = RQRCode::QRCode.new(params[:data] || 'https://qrcode.fun')
    svg = qr.as_svg(module_size: 6, standalone: true)

    render inline: svg, content_type: 'image/svg+xml'
  end
end
QRCode.fun API

Ruby에서 API로 QR코드 생성

Net::HTTP 또는 Faraday를 사용하여 Ruby에서 QRCode.fun API를 호출하여 스타일 QR코드를 생성하세요.

Ruby API 통합
require 'net/http'
require 'json'

uri = URI('https://qrcode.fun/api/generate-qr-styled')
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true

request = Net::HTTP::Post.new(uri)
request['Content-Type'] = 'application/json'
request.body = {
  data: 'https://qrcode.fun',
  width: 300,
  height: 300,
  type: 'png',
  margin: 10,
  dotsOptions: { color: '#1A2B3C', type: 'rounded' },
  cornersSquareOptions: { color: '#8564C3', type: 'extra-rounded' },
  backgroundOptions: { color: '#FFFFFF' }
}.to_json

response = http.request(request)
result = JSON.parse(response.body)
puts result['data'][0..49]

QR코드 라이브 미리보기

지금 바로 Ruby로 QR코드를 생성해 보세요.

QR 미리보기

네이티브 라이브러리 vs API

rqrcode와 QRCode.fun API 비교.

기능rqrcode GemQRCode.fun API
설정 복잡도gem install + 이미지용 ChunkyPNG단일 HTTP 요청
커스터마이징색상, 모듈 크기 (SVG/PNG)전체 스타일링: 색상, 모양, 로고
오프라인 지원인터넷 필요
유지보수bundle update항상 최신 상태
출력 형식SVG, PNG, ANSI 터미널PNG, SVG

Ruby QR코드 사용 사례

Ruby 애플리케이션에서 QR코드의 일반적인 시나리오.

Rails 애플리케이션

Rails 컨트롤러에서 사용자 프로필, 이벤트 티켓, 2단계 인증 설정을 위한 QR코드를 생성합니다.

백그라운드 작업

Sidekiq 또는 Active Job을 사용하여 비동기로 QR코드를 생성하여 배치 라벨 생성과 이메일 캠페인에 사용합니다.

API 엔드포인트

모바일 앱과 서드파티 통합을 위해 QR코드를 이미지 또는 SVG로 반환하는 API 엔드포인트를 구축합니다.

자동화 스크립트

재고, 자산 태깅, 이벤트 관리를 위해 QR코드를 대량 생성하는 Ruby 스크립트를 작성합니다.

자주 묻는 질문

Ruby로 QR코드 생성에 관한 일반적인 질문.

rqrcode가 가장 인기 있고 잘 유지보수되는 Ruby QR코드 gem입니다. SVG와 PNG 출력을 지원하며 Rails와 잘 통합됩니다.

Ruby로 QR코드 생성 시작하기

무료 생성기를 사용하거나 API를 Ruby 및 Rails 애플리케이션에 통합하세요.