ImageBoss Helper for Ruby
Official Gem for Generating ImageBoss URLs. https://imageboss.me/
Table of Contents
Installation
Add this line to your application's Gemfile:
bundle add imageboss-rb
Or install it yourself as:
gem install imageboss-rb
Usage
Example Image Resizing With Cover Operation
client = ImageBoss::Client.new(source: 'mywebsite')
image_url = client.path('/images/img01.jpg')
.operation(:cover, width: 100, height: 100)
#=> https://img.imageboss.me/mywebsite/cover/100x100/images/img01.jpg
Example Image Resizing With Height Operation
client = ImageBoss::Client.new(source: 'mywebsite')
image_url = client.path('/images/img01.jpg')
.operation(:height, height: 100)
#=> https://img.imageboss.me/mywebsite/height/100/images/img01.jpg
Example Image Resizing With Extra Options
client = ImageBoss::Client.new(source: 'mywebsite')
image_url = client.path('/images/img01.jpg')
.operation(:width, width: 100, options: { grayscale: true })
#=> https://img.imageboss.me/width/100/grayscale:true/images/img01.jpg
All operations and options for Image Resizing
It's all available on our Official Docs.
Disabling URL generation
If you are coding on test, development environments and don't want to send any image to ImageBoss
you can always disable the URL generation and the client will just fallback to the original path provided.
client = ImageBoss::Client.new(source: 'mywebsite', disabled: true)
image_url = client.path('/images/img01.jpg')
.operation(:width, width: 100, options: { grayscale: true })
#=> /images/img01.jpg
This will give you the ability to see your image without adding extra code to handle this situation.
Signing your URLs
Read more about this feature here: https://www.imageboss.me/docs/security
client = ImageBoss::Client.new(source: 'mywebsite', secret: '<MY_SECRET>')
image_url = client.path('/images/img01.jpg')
.operation(:width, width: 100)
#=> https://img.imageboss.me/width/100/images/img01.jpg?bossToken=ff74a46c7228ee4262c39b8d501c488293c5be9d433bb9ca957f32c9c3d844ab
This will give you the ability to see your image without adding extra code to handle this situation.
Tested on
Ruby
- 2.6.3
- 2.5.1
- 2.4.4
- 2.3.7
- 2.2.7
- 2.1.10
jRuby
- jruby-9.0.5.0
Rubinius
- rbx-3.100
