Difference between revisions of "Ruby"

From Wasya Wiki
Jump to: navigation, search
(Created page with " == Install ruby on ubuntu 20 == From: https://www.digitalocean.com/community/tutorials/how-to-install-ruby-on-rails-with-rbenv-on-ubuntu-20-04 sudo apt update sudo apt...")
 
Line 13: Line 13:
  
 
   type rbenv
 
   type rbenv
 +
 +
== How to render text on image with RMagick and Word wrap? ==
 +
From: https://stackoverflow.com/questions/11788216/how-to-render-text-on-image-with-rmagick-and-word-wrap
 +
 +
<pre>
 +
phrase = "my super long text that needs to be auto line breaked and cropped"
 +
background = Magick::Image.read('my_bg_img.jpg').first
 +
image = Magick::Image.read("caption:#{phrase}") do
 +
  self.size = '800x600' #Text box size
 +
  self.background_color = 'none' #transparent
 +
  self.pointsize = 22 # font size
 +
  self.font = 'Helvetica' #font family
 +
  self.fill = 'gray' #font color
 +
  self.gravity = Magick::CenterGravity #Text orientation
 +
end.first
 +
background.composite!(image, Magick::NorthEastGravity, 20, 40, Magick::OverCompositeOp)
 +
background.format = "jpeg"
 +
return background.to_blob
 +
</pre>

Revision as of 03:25, 12 March 2024

Install ruby on ubuntu 20

From: https://www.digitalocean.com/community/tutorials/how-to-install-ruby-on-rails-with-rbenv-on-ubuntu-20-04

 sudo apt update
 sudo apt install git curl libssl-dev libreadline-dev zlib1g-dev autoconf bison build-essential libyaml-dev libreadline-dev libncurses5-dev libffi-dev libgdbm-dev
 curl -fsSL https://github.com/rbenv/rbenv-installer/raw/HEAD/bin/rbenv-installer | bash
 echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc
 echo 'eval "$(rbenv init -)"' >> ~/.bashrc

Test:

 type rbenv

How to render text on image with RMagick and Word wrap?

From: https://stackoverflow.com/questions/11788216/how-to-render-text-on-image-with-rmagick-and-word-wrap

phrase = "my super long text that needs to be auto line breaked and cropped"
background = Magick::Image.read('my_bg_img.jpg').first
image = Magick::Image.read("caption:#{phrase}") do
  self.size = '800x600' #Text box size
  self.background_color = 'none' #transparent
  self.pointsize = 22 # font size
  self.font = 'Helvetica' #font family
  self.fill = 'gray' #font color
  self.gravity = Magick::CenterGravity #Text orientation
end.first
background.composite!(image, Magick::NorthEastGravity, 20, 40, Magick::OverCompositeOp)
background.format = "jpeg"
return background.to_blob