Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

croppable

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

croppable

  • 0.2.0
  • Rubygems
  • Socket score

Version published
Maintainers
1
Created
Source

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:install

The asset_host config needs to be set on every environment

config.asset_host = "http://localhost:3000"

Manual setup

Install cropperjs JavaScript dependency

yarn add cropperjs@next
// or
bin/importmap pin cropperjs@next

If 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 croppable

Install croppable migrations

bin/rails croppable:install:migrations

Install libvips

brew install vips

Usage

Add has_croppable into your model

has_croppable :logo, width: 300, height: 300, scale: 2

width 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 :logo

Update 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_original

NOTE: 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:system

License

The gem is available as open source under the terms of the MIT License.

FAQs

Package last updated on 10 Mar 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc