Giter Site home page Giter Site logo

carrierwave-crop's People

Contributors

kirtithorat avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

carrierwave-crop's Issues

Add the ability to generate javascript instead of coffeescript

Hello!

Would it be possible to generate javascript instead of coffeescript code for the image uploader? I know of several developers that prefer javascript to coffeescript, and I feel being able to provide that option would help make the gem for flexible and easier to use.

Incompatible with CarrierWave::Backgrounder

Would you consider making this gem compatible with CarrierWave Backgrounder and Delayed::Job?

The gem currently doesn't work with those, because it relies on virtual attributes as defined in crop_uploaded. These attributes are not persisted and since Delayed Job simply stores/retrieves the object by its ID these values will not be available when the processing happens.

I see two solutions for this:

One is solution is adding additional methods to ActiveRecord to serialize these virtual attributes for Delayed Job. This solution is described here, but doesn't seem particularly elegant.

The other solution is to actually store the crop attributes in the database, rather than using virtual attributes. This way the attributes persist and are available to the Delayed Job worker. The attributes can be set to nil once processing is completed so cropping? will only be true if the attributes are set again.

I've been able to make some progress on implementing the latter solution, but I'm still not 100% there yet. For some reason the images are only cropped when a new image is uploaded, but not when the crop attributes are changed.

Any suggestions on how to make it work, or how to debug it?

Add an option to disable auto-generation of `attr_accessor`s?

Hey,

I just wanted to know if you'd be okay with an option to disable the auto-generation of the attr_accessors for the X_crop_Y attributes. My use case needs me to save those, and I'd rather not have some glue code to save them in the model.

NoMethodError 'crop' in uploader

Hi,
I have an error on rails 4.2 using the gem carrierwave-crop 0.1.2.
when I try to crop the image an error occurs:

NoMethodError (undefined method `crop' for #LocationShowcaseUploader::Uploader70164076328740:0x007fa0b6842a98)

my code:

class LocationShowcase < ActiveRecord::Base
  # other stuff..

  mount_uploader :image, LocationShowcaseUploader, mount_on: :image_file_name
  crop_uploaded :image

  # other stuff..
end
class LocationShowcaseUploader < CarrierWave::Uploader::Base
  include CarrierWave::Compatibility::Paperclip
  include SharedUploader
  include CarrierWave::MiniMagick
  include CarrierWave::ImageOptimizer

  # other stuff..

  version :default do
    process resize_to_fit: [600, -1], optimize: [{ quality: 60 }]
  end

  version :large, if: :is_cropped? do
    process crop: :default
    process resize_to_fit: [1335, -1], optimize: [{ quality: 60 }]
  end

  version :medium, if: :is_cropped? do
    process crop: :default
    process resize_to_fit: [770, -1], optimize: [{ quality: 60 }]
  end

  version :small, if: :is_cropped? do
    process crop: :default
    process resize_to_fit: [610, -1], optimize: [{ quality: 60 }]
  end

  version :admin, if: :is_cropped? do
    process crop: :default
    process resize_to_fit: [-1, 70], optimize: [{ quality: 60 }]
  end

  private

  def is_cropped?(image)
    model.image_crop_x.present?
  end

end

How-to: Using carrierwave-crop w Mongoid

Hi everyone,
I just wanted point out that this gem can be used with Mongoid. All you have to do is to add necessary modules in the model; Just the two lines of code noted in following example.

class Profile

  include Mongoid::Document
  include Mongoid::Timestamps

  # Include these modules to use carreirwave-crop
  extend CarrierWave::Crop::ModelAdditions::ClassMethods
  include CarrierWave::Crop::ModelAdditions::InstanceMethods

  # ... rest of the model ...

  # you can use carrierwave-crop methods same way as before
  mount_uploader :avatar, AvatarUploader
  crop_uploaded :avatar

end

Cheers, Farzad.

Code breaks if image is large

Hi
I have a problem with your solution: If image is too large it's get resized by jCrop or browser ( didn't get quite well who is doing it ) ( For example when I tried 3000x2000 actually I get something near 1700x1400 ). And as a result cropped area is not as I expected ( it's smaller than you see in preview ).

I have Ad and photo instead of User and avatar, and using MiniMagick, so my monkey patch looked like this:

  1. I added photo_displayed_height and photo_displayed_width accessors to model which owns attachment, so I can store in it size of photo actually displayed in browser

  2. added them to form:

 = f.previewbox :photo, width: 100, height: 100
  =f.hidden_field :photo_displayed_height
  =f.hidden_field :photo_displayed_width
  1. added this code to coffee:
update: (coords) =>
    $('#ad_photo_displayed_height').val($('#ad_photo_cropbox').height())
    $('#ad_photo_displayed_width').val($('#ad_photo_cropbox').width()) 
  1. AND the most important part in processors I reprocess attributes ( it can be done also in the controller ):
version :thumb do
    process :transform_crop_attributes
    process crop: :photo  ## Crops this version based on original image
    resize_to_limit(100,100)
  end

  def transform_crop_attributes
    if file && model
      real_width, real_height = MiniMagick::Image.open(file.file)[:dimensions]
      if real_height != model.photo_displayed_height || real_width != model.photo_displayed_width
        [:photo_crop_y, :photo_crop_w].each do |attr|
          model.send(attr) && model.send("#{attr}=", model.send(attr).to_i * real_height.to_i / model.photo_displayed_height.to_i )
        end
        [:photo_crop_x, :photo_crop_h].each do |attr|
          model.send(attr) && model.send("#{attr}=", model.send(attr).to_i * real_width.to_i / model.photo_displayed_width.to_i )
        end
      end
    end
  end

Error when submitting nested form images with a model

I have a model A that uses Carrierwave Crop and when I submit a nested form that includes multiple model Bs that has an image, I get the following error. Character is Model B.

Model A has many Model B and Model B belongs to Model A

undefined method `image_coverpage_crop_x' for #<Character:0x007fcfdd064528>
if @vn.update(vn_params) // This is the line that raises the error

I have ensured that the strong params in Model A includes the cropping fields and that it allows nested attributes. Everything works fine if I update Model A by itself or Model B by itself. Updating all of them at the same time causes the error.

Rails5 support

Can't update my rails app due to this gem depends on

    carrierwave-crop was resolved to 0.1.2, which depends on
      rails (>= 3.2)

Colons in html id attributes

Hi and thanks for this great gem.
I have found a little problem that appears when I am using Namespaced Models.
This causes the previewbox and cropbox helper to create html tags with colons "::" inside the id attribute.
For example if my model is Asset::Image and my attachement is file, the helpers will create tags with the ids "asset::image_file_previewbox" and "asset::image_file_cropbox".
Although this is valid according to w3c, this causes some problems when you try to access these attributes by jquery, because you have to escape all colons with a double backslash linke this:

$('#asset\\:\\:image_file_cropbox').Jcrop

It also differs from the rails convention, that only uses underscores as delimiter inside html ids.

Maybe it would be enough to replace all double colons "::" inside "model_name" in helpers.rb with one underscore

Can't crop depending on the order of the crop's params

Whenever using accepts_nested_attributes_for and within its hash params, when the Carrierwave field comes as first the attribute, the cropping doesn't work. It only works when it is the last.

For example, this works (picture params (Carrierwave's) as last) :

Project.create "pictures_attributes"=>{
  "0"=>{
    "picture_crop_x"=>"0", 
    "picture_crop_y"=>"0", 
    "picture_crop_w"=>"200", 
    "picture_crop_h"=>"200", 
    "picture"=> File.open('/path/img.png')
  }
}, "name"=>"A name"

And this doesn't work (picture params as first):

Project.create "pictures_attributes"=>{
  "0"=>{
    "picture"=> File.open('/path/img.png'), 
    "picture_crop_x"=>"0", 
    "picture_crop_y"=>"0", 
    "picture_crop_w"=>"200", 
    "picture_crop_h"=>"200" 
  }
}, "name"=>"A name"

I haven't tried for regular params, only for the accepts_nested_attributes_for.

Version Dependency conflict with carrierwave

  • Using carrierwave

gem 'carrierwave', github: 'carrierwaveuploader/carrierwave'

I'm getting the following error:

Bundler could not find compatible versions for gem "carrierwave":
  In Gemfile:
    carrierwave

    carrierwave-crop was resolved to 0.1.2, which depends on
      carrierwave (< 0.11.0, >= 0.8.0)

I cannot use 0.10 as it does not support multiple file uploads, which i need.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.