rsantamaria / papercrop Goto Github PK
View Code? Open in Web Editor NEWAn easy extension for Paperclip to crop your image uploads using jCrop.
An easy extension for Paperclip to crop your image uploads using jCrop.
I'm using now paperclip and papercrop
but this issue happened on f.cropbox of new event page .
url: ...events/new
error message: Paperclip::Errors::NotIdentifiedByImageMagickError
how to solve this issue?
Update CSS to use rails helper:
image_url('Jcrop.gif')
I want to use the crop action to upload profile pictures for users. If i stay on the profile page, it works perfectly and i am able to crop and upload a picture. But if move to home page, and then go back to profile page where the form is, the cropbox brokes and shows the original picture in full size instead, and the only way to get it back is reloading the page.
Maybe this images can help:
At first visit on the profile:
After go other section and come back:
My code is simple:
<%= form_for(current_user, :url => '/crop_image',:method=>"PUT", id:"form-avatar") do |f| %> <%= f.cropbox :avatar, :width => 550,:height => 550 %>
Hi, I'm getting
Can't mass-assign protected attributes: photo_original_w, photo_original_h, photo_box_w, photo_crop_x, photo_crop_y, photo_crop_w, photo_crop_h, photo_aspect
when I try to save the user after cropping an avatar picture, what I am doing wrong?
Is there a way to not crop every style?
I am trying to show the cropped image after cropping but does not find any relevant thing to show can you please help me.
Paperclip 4.2.1
The thumbs aren't being cropped correctly. I actually have a thumbnail size at 100x100, but a blank 1x1 image is created.
Does Papercrop account for the fact that the original image when shown in the cropper is resized down to fit the screen?
Error installing papercrop: activesupport requires Ruby version >= 2.2.2
I don't work with as images when it is rotation 0 deg (bad english)
I have a model that has has two attachments and as I wanted to crop both attachments on the same view I came across a bug.
The second time the method image_geometry is called (even for different attachments) returns the same result as the first time because the result is stored in a instance variable and it is not scoped by the attachment name.
If this is really a bug I would be more than happy to submit a pull request to fix it.
Papercrop was working well with localhost, but when I try to load the crop form with amazon s3, I got this error
Paperclip::Errors::NotIdentifiedByImageMagickError
users/avatars/original/20.jpg is not recognized by the 'identify' command.
So Is papercrop doesn't support amazon s3 or what's going on here?
Hello,
I'm using your gem with paperclip 3.5 on a rails 4 application and all is going fine but the picture saved under S3 are not cropped.
Here's the log. What I'm missing?
Processing by ImgProcessingController#crop_edit_agency as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"RCvVsN3am+OIFMfYXEAub9h1ZIEMs/p9Ib1rc4JkNJM=", "edit_agency"=>{"cover_pic_original_w"=>"2048.0", "cover_pic_original_h"=>"1369.0", "cover_pic_box_w"=>"700", "cover_pic_crop_x"=>"0", "cover_pic_crop_y"=>"263", "cover_pic_crop_w"=>"2048", "cover_pic_crop_h"=>"701", "cover_pic_aspect"=>"2.9197080291970803"}, "commit"=>"Submit cropped cover picture", "id"=>"62"}
User Load (1.2ms) SELECT "users".* FROM "users" WHERE "users"."id" = 10 ORDER BY "users"."id" ASC LIMIT 1
LinkedinProfile Load (0.5ms) SELECT "linkedin_profiles".* FROM "linkedin_profiles" WHERE "linkedin_profiles"."user_id" = $1 ORDER BY "linkedin_profiles"."id" ASC LIMIT 1 [["user_id", 10]]
EditAgency Load (0.8ms) SELECT "edit_agencies".* FROM "edit_agencies" WHERE "edit_agencies"."id" = $1 LIMIT 1 [["id", "62"]]
(0.3ms) BEGIN
[paperclip] copying /edit_agencies/cover_pics/000/000/062/original/1071315_10153070566640187_1979155193_o.jpg to local file /var/folders/kd/hfx1g5ts4354ctfgc_x7l93m0000gn/T/1071315_10153070566640187_1979155193_o20140221-7855-zs5rj9.jpg
[AWS S3 200 0.763641 0 retries] get_object(:bucket_name=>"magicagencies-test",:key=>"edit_agencies/cover_pics/000/000/062/original/1071315_10153070566640187_1979155193_o.jpg")
[AWS S3 200 0.043105 0 retries] head_object(:bucket_name=>"magicagencies-test",:key=>"edit_agencies/cover_pics/000/000/062/original/1071315_10153070566640187_1979155193_o.jpg")
[paperclip] deleting /edit_agencies/cover_pics/000/000/062/original/1071315_10153070566640187_1979155193_o.jpg
[AWS S3 204 0.049076 0 retries] delete_object(:bucket_name=>"magicagencies-test",:key=>"edit_agencies/cover_pics/000/000/062/original/1071315_10153070566640187_1979155193_o.jpg")
[paperclip] saving /edit_agencies/cover_pics/000/000/062/original/1071315_10153070566640187_1979155193_o.jpg
[AWS S3 200 0.185554 0 retries] put_object(:acl=>:public_read,:bucket_name=>"magicagencies-test",:content_length=>221684,:content_type=>"image/jpeg",:data=>Paperclip::AttachmentAdapter: 1071315_10153070566640187_1979155193_o.jpg,:key=>"edit_agencies/cover_pics/000/000/062/original/1071315_10153070566640187_1979155193_o.jpg")
Cropping is working perfect in case of save images on local but we have tried to save images on s3 browser after crop. All styles images has been removed from the s3 browser.
What is the process of saving a crop images on s3 browser ???
It would be great help if any one help me out.
Thanks in advance
The UI component works flawlessly, and I think I can see traces of the cropping working, but the resulting saved image is the original unchanged. The problem is described in detail here : http://stackoverflow.com/questions/35694968/papercrop-is-not-saving-cropped-image
I'm getting the above error message when clicking save from the crop image screen. I'm using the default form code for the preview / crop screen.
When hitting save I'm getting "wrong number of arguments (1 for 0)"
Looking at the error log, the error is being flagged on:
papercrop (0.3.0) lib/papercrop/model_extension.rb:124:in
reprocess_cropped_attachment'`
Looking at that line the issue is in
if cropping?(attachment_name)
which looks like it should be expecting an argument, and the value of attachment_name is the correct attachment name.
I'm currently using Paperclip 4.2.1 (I've tried downgrading Paperclip to 3.4, just incase it was Paperclip issue, but still getting the error).
If you've any ideas to what the issue is or any suggestions to get to the root of the problem, they'd be most welcome.
Thanks
I believe minified Jcrop should be incorporated, or should be provided as alternative.
Any plans to update this for Paperclip 4.1? I've tried to get started myself but don't know this library (or paperclip) all that well.
I'm not sure that this is a papercrop issue, it might be a paperclip one but I start from here because I suspect that if it were a paperclip issue it would have surfaced a long time ago. I'm using paperclip 4.2.0 and papercrop 0.2.0.
I have a model user.rb with
class User < ActiveRecord::Base
extend FriendlyId
friendly_id :slug_candidates, use: [ :slugged, :finders ]
def slug_candidates
...
end
Paperclip.interpolates :slug do |attachment, style|
attachment.instance.slug
end
has_attached_file :picture,
styles: { large: "512x512!", medium: "256x256!", thumb: "128x128!", status: "32x32!" },
default_url: "/images/:class/:style/missing.png",
hash_secret: "whatever-it-is",
url: "/system/:class/:attachment/:slug/:style/:hash.:extension",
path: ":rails_root/public/system/:class/:attachment/:slug/:style/:hash.:extension"
crop_attached_file :picture
plus some devise declarations and some associations which probably don't matter.
Note that I'm using :hash
in the path. This is important.
I'm displaying the cropper with the default form code from the README
<%= form_for @user do |f| %>
<%= f.cropbox :picture %>
<%= f.crop_preview :picture %>
<%= f.submit 'Save' %>
<% end %>
It updates the images but when I reload the page with the form I get Paperclip::Errors::NotIdentifiedByImageMagickError
in the f.cropbox line.
The stack trace is
paperclip (4.2.0) lib/paperclip/geometry_detector_factory.rb:10:in `make'
paperclip (4.2.0) lib/paperclip/geometry.rb:26:in `from_file'
papercrop (0.2.0) lib/papercrop/model_extension.rb:71:in `image_geometry'
papercrop (0.2.0) lib/papercrop/helpers.rb:41:in `cropbox'
app/views/users/show.html.erb:9:in `block in _app_views_users_show_html_erb___579696657148981651_70039981047720'
(Yes, I put the form in show view but I'm only testing the gem)
The reason for that ImageMagick error is that the file name passed to the identify command doesn't exist.
After some debugging I realized that the problem is due to either papercrop or paperclip did not update the picture_updated_at field in the database. In turn that makes paperclip generate the wrong hash for the path and the url of the updated picture. Hence the error.
I worked around this issue by manually saving the attribute in the controller
if @user.update_attributes(user_params)
@user.update_column(:picture_updated_at, @user.picture_updated_at)
redirect_to users_path, alert: "User updated"
else
render :edit
end
Note that @user.picture_updated_at has the correct timestamp. It doesn't make its way to the database.
Should I open this issue on the paperclip repository or is this something worth investigating in papercrop?
By the way, I found something similar at http://stackoverflow.com/questions/20429449/paperclip-attachment-not-using-proper-updated-at-time-for-query-string solved with a similar workaround. However that was with paperclip 2.7
I have 2 database tmp_img which is cropped and i want to save this object to another database with the same image sizes:
container = Container.new
container.image = tmp_img.image
container.save
image is saved without crop
On the edit_user_registration_path with Devise, I am trying to use Papercrop to change the user's avatar. I'm getting the error message --- undefined method `delete' for :avatar:Symbol
It is cropping okay, but I had to modify the Devise setup to allow the update to save as well, so I'm not sure if that is part of the problem. Anyhow, it is not saving. Any suggestions? Thanks :)
I have the crop set up as recommended in the README, but the preview is showing a much zoomed in image, which is also being saved. How can I get the two images to match in size / zoom? This would be very helpful, thanks!
I'm trying to set up Papercrop as per the readme but it's not working. I've added the Paperclip columns to my database, the has_attached_file
and crop_attached_file
lines to my model, and the f.cropbox
and f.crop_preview
lines to my user edit form, but when I try to visit the page I get a Paperclip::Errors::NotIdentifiedByImageMagickError
- "Cannot find the geometry of a file with a blank name".
This is for an avatar
attribute on a User
model which uses Devise... I just copied the same code into the edit page for one of my other models which already has a paperclip attachment, and it works fine. So it seems there's a conflict between Paperclip and Devise, but I don't know enough about either to know where to start debugging.
Just a quick note to document an issue I was having—nothing to do with the gem itself, but how it worked inside of a project using Zurb Foundation.
The crop preview was always stuck at 100% width which made it look like it was broken. The image would crop correctly though, so I narrowed down the issue to the CSS attributes being set by the papercrop.js file. I saw that those were being set correctly as well, which led me to look for a style that was overriding what was being set, which led me to Foundation.
In Foundation, all images are set to: min-width: 100%, so to fix this, I had to override the crop_preview image with:
max-width: none !important;
Note: for my application, the image had an id of #image_crop_preview, but that will differ based on what you've called your attachment.
I think having ability to set minimum crop size would be pretty useful, so that images do not have to be up scaled if user selects too small an area.
I followed all steps required but sometimes when I resize the cropper and save image it crops image correctly and saves correct "Original" image but small, thumbnail, large this variants of same image are getting saved as black color block.
image style types: small, medium, large, thumbnail
has_attached_file :header_image, styles: { small: "720x300#", medium: "1440x600#", large: "2880x1200#",thumbnail: "360x360#", original: {convert_options: '-strip'} }, default_url: "/assets/missing1.png", hash_data: ":class/:attachment/:id/:style", path: '/:class/:attachment/:id_partition/:style/:hash', hash_secret: PAPERCLIP_HASH_SECRET crop_attached_file :header_image, :aspect => "12:5" validates_attachment_content_type :header_image, :content_type => ["image/jpg", "image/jpeg", "image/png", "image/gif"]
Some companies will only use gems with a certain license.
The canonical and easy way to check is via the gemspec,
via e.g.
spec.license = 'MIT'
# or
spec.licenses = ['MIT', 'GPL-2']
Even for projects that already specify a license, including a license in your gemspec is a good practice, since it is easily
discoverable there without having to check the readme or for a license file. For example, it is the field that rubygems.org uses to display a gem's license.
For example, there is a License Finder gem to help companies ensure all gems they use
meet their licensing needs. This tool depends on license information being available in the gemspec. This is an important enough
issue that even Bundler now generates gems with a default 'MIT' license.
If you need help choosing a license (sorry, I haven't checked your readme or looked for a license file), github has created a license picker tool.
In case you're wondering how I found you and why I made this issue, it's because I'm collecting stats on gems (I was originally looking for download data) and decided to collect license metadata,too, and make issues for gemspecs not specifying a license as a public service :).
I hope you'll consider specifying a license in your gemspec. If not, please just close the issue and let me know. In either case, I'll follow up. Thanks!
p.s. I've written a blog post about this project
I tried to use papercrop with Paperclip 3.4.0. Unfortunately, the after_update callback gets into the endless loop - Paperclip updates photo metadata columns after reprocess and the hook is launched again and again...
As a simple workaround I have done this:
In the model:
crop_attached_file :photo, :aspect => '1:1'
def reprocess_to_crop_photo_attachment
end
...I have created empty callback method to prevent automatic reprocess invocation.
Then, in the controller, I manually launch the reprocess routine:
def update
...
resource.photo.reprocess! if resource.cropping?('photo')
...
end
Maybe it would be better to switch the default behaviour of the gem to manual reprocess invocation. To have it automatic, it would be necessary to add some checking into the callback method, so that it is not launched over and over again.
anyway, thanks for great gem!
Jakub Cerny
Hey,
I just wonder why the papercrop doesn't work after I render the form via ajax call, so I have a button like this which call picture_crop action remotely
<%=link_to "crop","/users/picture_crop", :remote => true%>
then in the action I response with a javascript file ruby picture_crop.erb.js
def picture_crop
respond_to do |format|
format.js
end
end
picture_crop.erb.js
$('body').html($('<%= escape_javascript(render(:file => "users/picture_crop.html.erb"))%>'));
users/picture_crop.html.erb
<%= form_for current_jobseeker, :url => "/users/#{current_jobseeker.id}", :html => { :multipart => true, :id => "crop_form" } do |f| %>
<%= f.cropbox :avatar, :width => 500 %>
<%= f.crop_preview :avatar, :width => 100 %>
<%= f.submit "Crop" %>
<% end %>
but the form is loaded without any functionality of jCrop, so I can't select specific area of the photo, and also the width of the photo and preview doesn't match what I passed in the form.
by the way the form is working fine with page reload, so the problem is only with ajax call, so any help please what can I do here to solve this problem?
I just want to make the aspect ratio unconstrained so the user can select whatever s(he) need. The default is 1:1. so How Can I set it to be like this just like this demo http://deepliquid.com/projects/Jcrop/demos.php
Thanks for the gem! a big help for the js newbs like myself. Got everything working... except the original image being too big for mobile views.
Any tips on how to get it to be responsive?
Sorry i'm new to testing gem and appraisal.
After installation of Gemfile's dependencies with appraisal i try to do appraisal rake but i get this LoadError:
>> BUNDLE_GEMFILE=/Users/ale/Sites/papercrop/gemfiles/rails_3_2.gemfile bundle exec rake /Users/ale/.rvm/gems/ruby-2.2.1/gems/activesupport-3.2.13/lib/active_support/values/time_zone.rb:270: warning: circular argument reference - now /Users/ale/.rvm/rubies/ruby-2.2.1/bin/ruby -S rspec ./spec/helpers/form_helpers_spec.rb ./spec/integration/papercrop_js_spec.rb ./spec/integration/papercrop_spec.rb ./spec/model_extensions/model_extension_spec.rb ./spec/model_extensions/reg_exp_spec.rb /Users/ale/.rvm/gems/ruby-2.2.1/gems/activesupport-3.2.13/lib/active_support/values/time_zone.rb:270: warning: circular argument reference - now /Users/ale/.rvm/gems/ruby-2.2.1/gems/activesupport-3.2.13/lib/active_support/dependencies.rb:251:in require': cannot load such file -- test/unit/assertions (LoadError)
What can i do to solve this issue?
Thanks!
Hey there, thanks for the awesome plugin!
Right now I'm using the plugin in my app to crop profile pictures. The issue is that some people upload really large photos, which makes Papercrop break (zoom issue, offcenter crop issue).
So my solution has been to process the images down to >1000px wide in Paperclip, and then I'd like to pass Papercrop that version of the image. But when I pass Papercrop @card.photo.url(:croppable), I get an undefined method error. I've tried a few other syntax ideas too, no luck.
How can I pass a processed version of my image to papercrop?
Thanks again for all your work on this gem my friend!
I'd like to display the dimensions of the cropped image in real time, as the crop gets changed. There are input fields #pic_crop_{n} where n is x, y, w, and h.
These input fields get their values updated as the crop box changes, however, they do not trigger a change() so there's no way to bind onto it and display their values (at least not nicely).
Please either make this a configuration option or at least trigger change() events when these inputs are updated so they can be used elsewhere.
Hi) I have different models user and profile, and it doesn't crop when i pass params through user's form with nested attributes
"user"=>{"profile_attributes"=>{"avatar_original_w"=>"517", "avatar_original_h"=>"517", "avatar_box_w"=>"500", "avatar_aspect"=>"1.0", "avatar_crop_x"=>"0", "avatar_crop_y"=>"0", "avatar_crop_w"=>"517", "avatar_crop_h"=>"517", "id"=>"11"}}
With paperclip 3.5 the code fails when calling 'attachment_definitions' method - probably the last paperclip refactoring changed that...
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.