# frozen_string_literal: true
class UserUploader < ApplicationUploader
include CarrierWave::MiniMagick
def generate_image(text)
tmp_path = File.join(Dir.tmpdir, "#{SecureRandom.hex}.png")
MiniMagick::Tool::Convert.new do |img|
img.size "500x200"
img.xc "white" # Background color
img.gravity "Center" # Center the text
img.pointsize "36" # Font size
img.fill "black" # Text color
img.draw "text 0,0 '#{text}'"
img.font "#{Rails.root.join('public', 'font', 'Franklin_Gothic_Heavy_Regular.ttf')}"
img << tmp_path # Save image to this path
end
File.open(tmp_path) # Return file handle
end
end
Estou enviando parâmetros do frontend e a fonte que estou usando no frontend é Franklin_Gothic_Heavy_Regular.ttf definida em app/assets/fonts/Franklin_Gothic_Heavy_Regular.ttf
Para usá-lo no carregador, adicionei o mesmo arquivo de fonte em public/font/Franklin_Gothic_Heavy_Regular.ttf, mas quando a imagem é armazenada, ela não mostra a fonte correta.
Estou usando vuejs no front-end e rails no back-end. Por favor, me ajude a consertar isso.
Informações do ImageMagick
Version: ImageMagick 7.1.0-58 Q16-HDRI x86_64 20802 https://imagemagick.org
Copyright: (C) 1999 ImageMagick Studio LLC
License: https://imagemagick.org/script/license.php
Features: Cipher DPC HDRI Modules OpenMP(5.0)
Delegates (built-in): bzlib fontconfig freetype gslib heic jng jp2 jpeg jxl lcms lqr ltdl lzma openexr png ps raw tiff webp xml zlib
Compiler: gcc (4.2)
coloca img.command.join(" ") retorna
magick convert -size 500x200 xc:white -gravity Center -pointsize 36 -fill black -draw text 0,0 'Testing Font' -font /Users/Documents/work/company/public/font/Franklin_Gothic_Heavy_Regular.ttf /var/folders/tc/3b0wh1xs7z7dms5rxj1l23_00000gn/T/74a90ba3c194bda014cb2706a3fcdd32.png