croppable
v0.2.2
Published
Easily crop images in Ruby on Rails with Cropper.js integration
Readme
Croppable
Easily crop images in Ruby on Rails with Cropper.js integration.
Installation
Add this line to your application's Gemfile:
gem "croppable"Setup
bin/rails croppable:installManual setup
Install cropperjs JavaScript dependency
yarn add cropperjs@next
// or
bin/importmap pin cropperjs@nextIf you're using importmap add croppable pin to importmap.rb
pin "croppable"Import the croppable JavaScript module in your application entrypoint
import "croppable"Import croppable styles in your base stylesheet
*= require croppableInstall croppable migrations
bin/rails croppable:install:migrationsInstall libvips
brew install vipsUsage
Add has_croppable into your model
has_croppable :logo, width: 300, height: 300, scale: 2width and height are in pixels and required.
scale: 2 will generate an image twice as big. Useful for retina display monitors. It defaults to 1.
Add croppable_field to your form
form.croppable_field :logoUpdate controller strong paramenters to permit each croppable parameter
params.require(:model).permit(..., :logo)Display cropped image in your view
image_tag model.logo if model.logo.present?Original image can be accessed in <croppable>_original
model.logo_originalNOTE: Images are cropped in a background job after model gets saved so they might not be immediately available
Contributing
Run all test
rails test
rails app:test:systemLicense
The gem is available as open source under the terms of the MIT License.
