Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how to add a label to an image? #150

Closed
jedschneider opened this issue Jun 14, 2013 · 4 comments
Closed

how to add a label to an image? #150

jedschneider opened this issue Jun 14, 2013 · 4 comments

Comments

@jedschneider
Copy link

From reading the source I would think I would use the combine_options method to invoke the internal CommandBuilder class, but I'm getting a little lost in the metaprogramming there and I don't know imagemagick that well to have a feel for how it might look.

here's my attempt that doesn't seem to work.

image.combine_options("label") do |c|
  c.label = "foo"
end

maybe I overlooked an example in the readme that does something similar. if not, perhaps an addition would be handy, which i'd be happy to write once I know how it works. thanks.

@jedschneider
Copy link
Author

looking here in the imagemagick docs: http://www.imagemagick.org/Usage/text/#label

@jedschneider
Copy link
Author

this is pretty straight forward once you understand how to translate the morgify options into block commands

      image.combine_options do |i|
        i.font "Helvetica"
        i.gravity "South"
        i.pointsize 14
        i.draw "text 0,0 'foo'"
      end

@lanrion
Copy link

lanrion commented Dec 29, 2015

@jedschneider It can't support ZH-CN, have other suggestions? e.g:

res_img = MiniMagick::Image.new("tmp/test_qrcode1.jpg")
res_img.combine_options do |i|
  i.font "Helvetica"
  i.pointsize 14
  i.encoding "GB2312"
  i.label:"我.utf8"
  i.draw "text 110,180 'DHH我.utf8'"
end

Thanks.

@coderliu
Copy link

coderliu commented Oct 9, 2016

@lanrion

img.combine_options do |i|
    i.font "#{Rails.root}/public/Songti.ttc"  #path to font file which support ZH-CN
    i.pointsize 14
    i.encoding "GB2312"
    i.label:"我.utf8"
    i.draw "text 110,180 'DHH我.utf8'"
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants