Skip to content

Latest commit

 

History

History
56 lines (38 loc) · 1.27 KB

README.md

File metadata and controls

56 lines (38 loc) · 1.27 KB

CarrierWave::DataUri

Carrierwave plugin that allows create image from data uri

Installation

Add this line to your application's Gemfile:

gem 'carrierwave-data-uri'

And then execute:

$ bundle

Or install it yourself as:

$ gem install carrierwave-data-uri

Usage

class User < ActiveRecord::Base
  mount_uploader :avatar, AvatarUploader
end

Then we can create image from data

user = User.find 123
user.avatar_data_uri = 'data:image/gif;base64,R0lGODlhAQABAJEAAAAAAP////8AAP///yH5BAEAAAMALAAAAAABAAEAAAICVAEAOw=='
user.save

Optionally, to customize the file name, specify the #{column}_data_filename attribute before the #{column}_data_uri attribute.

user = User.find 123
user.avatar_data_filename = 'somefile.jpg'
user.avatar_data_uri = 'data:image/gif;base64,R0lGODlhAQABAJEAAAAAAP////8AAP///yH5BAEAAAMALAAAAAABAAEAAAICVAEAOw=='
user.save

Contributing

  1. Fork it ( https://github.com/[my-github-username]/carrierwave-data-uri/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request

Credits