rails + paperclip + plupload - ruby-on-rails

Hi i'm using paperclip and plupload like in this tutorial:
http://www.theroamingcoder.com/node/50
It works.
But if i try to set thumbnails with paperclip like:
has_attached_file :data,
:styles => { :medium => "558x418>", :thumb => "60x82>" }
It doesn't work.
I receive this error:
[paperclip] identify -format %wx%h '/tmp/stream20110209-26212-1l2obtp-0.png[0]' 2>/dev/null
[paperclip] convert '/tmp/stream20110209-26212-1l2obtp-0.png[0]' -resize "558x418>" '/tmp/stream20110209-26212-1l2obtp-020110209-26212-cl5lbg-0' 2>/dev/null
[paperclip] An error was received while processing: #<Paperclip::PaperclipError: There was an error processing the thumbnail for stream20110209-26212-1l2obtp-0>
[paperclip] identify -format %wx%h '/tmp/stream20110209-26212-1l2obtp-0.png[0]' 2>/dev/null
[paperclip] convert '/tmp/stream20110209-26212-1l2obtp-0.png[0]' -resize "60x82>" '/tmp/stream20110209-26212-1l2obtp-020110209-26212-1m6qvkj-0' 2>/dev/null
[paperclip] An error was received while processing: #<Paperclip::PaperclipError: There was an error processing the thumbnail for stream20110209-26212-1l2obtp-0
How can i solve it?
thanks

It looks like you don't have Imagemagick installed!
http://www.imagemagick.org/script/index.php
If I am wrong try this
has_attached_file :data, :styles => { :medium => ["558x418>", :png], :thumb => ["60x82>", :png] }

I had to disable chunks in plupload

Related

PaperClip gem Paperclip::Errors::NotIdentifiedByImageMagickError

There are numerous Stackoverflow questions regarding this, but after many hours, I've exhausted every angle I could think of, and still get the following error when I try to upload an image using the PaperClip gem (in tandem with PaperCrop, for cropping the image).
Paperclip::Errors::NotIdentifiedByImageMagickError - Paperclip::Errors::NotIdentifiedByImageMagickError:
paperclip (4.3.6) lib/paperclip/geometry_detector_factory.rb:10:in `make'
paperclip (4.3.6) lib/paperclip/geometry.rb:26:in `from_file'
papercrop (0.3.0) lib/papercrop/model_extension.rb:95:in `image_geometry'
papercrop (0.3.0) lib/papercrop/helpers.rb:45:in `cropbox'
app/views/users/_crop_photo_modal.html.haml:12:in `block in _app_views_users__crop_photo_modal_html_haml___1410212035753490924_70365684359680'
Here is what prints in the logs just prior to the error:
[AWS S3 200 0.554305 0 retries] head_object(:bucket_name=>"XXX-development-bucket-us",:key=>"profiles/profile_images/1/original/main_sized_small.png")
[AWS S3 200 0.049585 0 retries] head_object(:bucket_name=>"XXX-development-bucket-us",:key=>"profiles/profile_images/1/thumb/main_sized_small.png")
[AWS S3 200 0.053507 0 retries] head_object(:bucket_name=>"XXX-development-bucket-us",:key=>"profiles/profile_images/1/medium/main_sized_small.png")
[AWS S3 200 0.048024 0 retries] head_object(:bucket_name=>"XXX-development-bucket-us",:key=>"profiles/profile_images/1/large/main_sized_small.png")
Command :: PATH=/usr/local/bin/:$PATH; file -b --mime '/tmp/3aa49ec6bfc910647fa1c5a013e48eef20160601-82031-t5fq8a.png'
Command :: PATH=/usr/local/bin/:$PATH; identify -format '%wx%h,%[exif:orientation]' '/tmp/3aa49ec6bfc910647fa1c5a013e48eef20160601-82031-1kh6s2w.png[0]' 2>/dev/null
Command :: PATH=/usr/local/bin/:$PATH; identify -format %m '/tmp/3aa49ec6bfc910647fa1c5a013e48eef20160601-82031-1kh6s2w.png[0]'
Command :: PATH=/usr/local/bin/:$PATH; convert '/tmp/3aa49ec6bfc910647fa1c5a013e48eef20160601-82031-1kh6s2w.png[0]' -auto-orient -resize "50x" -crop "50x50+0+0" +repage '/tmp/96994f01b3cacc5ddb9ed35b539d8c0420160601-82031-1n0cfvq'
Command :: PATH=/usr/local/bin/:$PATH; identify -format '%wx%h,%[exif:orientation]' '/tmp/3aa49ec6bfc910647fa1c5a013e48eef20160601-82031-1kh6s2w.png[0]' 2>/dev/null
Command :: PATH=/usr/local/bin/:$PATH; identify -format %m '/tmp/3aa49ec6bfc910647fa1c5a013e48eef20160601-82031-1kh6s2w.png[0]'
Command :: PATH=/usr/local/bin/:$PATH; convert '/tmp/3aa49ec6bfc910647fa1c5a013e48eef20160601-82031-1kh6s2w.png[0]' -auto-orient -resize "100x" -crop "100x100+0+0" +repage '/tmp/96994f01b3cacc5ddb9ed35b539d8c0420160601-82031-1fnck50'
Command :: PATH=/usr/local/bin/:$PATH; identify -format '%wx%h,%[exif:orientation]' '/tmp/3aa49ec6bfc910647fa1c5a013e48eef20160601-82031-1kh6s2w.png[0]' 2>/dev/null
Command :: PATH=/usr/local/bin/:$PATH; identify -format %m '/tmp/3aa49ec6bfc910647fa1c5a013e48eef20160601-82031-1kh6s2w.png[0]'
Command :: PATH=/usr/local/bin/:$PATH; convert '/tmp/3aa49ec6bfc910647fa1c5a013e48eef20160601-82031-1kh6s2w.png[0]' -auto-orient -resize "220x" -crop "220x220+0+0" +repage '/tmp/96994f01b3cacc5ddb9ed35b539d8c0420160601-82031-e3r9iy'
Command :: PATH=/usr/local/bin/:$PATH; file -b --mime '/tmp/3aa49ec6bfc910647fa1c5a013e48eef20160601-82031-ub7nk7.png'
(0.4ms) ROLLBACK
Command :: PATH=/usr/local/bin/:$PATH; identify -format '%wx%h,%[exif:orientation]' 'https://XXX-development-bucket-us.s3.amazonaws.com/profiles/profile_images/1/original/blake.png?1464811715[0]' 2>/dev/null
My environment:
paperclip v4.3.6
papercrop v0.3.0
aws-sdk v1.66.0
Rails 4.0.0
Ruby 2.0.0p643
Amazon S3 for file storage
OS-X Yosemite 10.10.5 (same error occurs on Heroku Linux server)
I have tried the following:
Use aws-sdk version 2 or higher.
Uninstall all imagemagick installs (I had 2 originally), and reinstall imagemagick with brew install imagemagick
Downgrade PaperClip to 4.1.1
Include :s3_credentials and :s3_permissions directly in the model, as follows:
has_attached_file :profile_image,
:styles => { :thumb => "50x50#", :medium => "100x100#", :large => "220x220#" },
:storage => :s3,
:s3_credentials => {:bucket => "XXX-development-bucket-us", :access_key_id => "XXX", :secret_access_key => "XXX"},
:s3_permissions => "public-read",
:default_url => '/images/:attachment/missing_:style.jpg'
validates_attachment :profile_image, content_type: { content_type: ["image/jpg", "image/jpeg", "image/png"] }
crop_attached_file :profile_image, :aspect => "1:1"
I thought it might be an s3 permissions problem, but the permissions on our development bucket should allow all access to the user identified by the keys.
I've also added...
Paperclip.options[:command_path] = "/usr/local/bin"
...to environments/development.rb.
I've verified ImageMagick is working on the commandline.
Any ideas what else to look at?
Yes, there are many exiting answers for this with different suggestions. But I tried out every possible solution for a day and arrived at the solution which fixed for me.
Ubuntu 12.04,Paperclip ~> '4.2'
Initially I was having ImageMagick 6.6.9-7 2016-06-01 Q16, updating this to ImageMagick 7.0.3-1 Q16 x86_64 2016-09-27 fixed it.
Note: Try installing the Imagemagick manually using wget http://www.imagemagick.org/download/ImageMagick.tar.gz

Paperclip for both images and Videos

In my app I already have paperclip for upload images, but requirement changed in order to accept both images and videos. The images are already defined in a model with a belongs_to relationship, called Attachment. Since the video will also be an attachment of the same parent model (in my case, articles) I wanted to reuse the same Attachment model for images & videos. Is this a good idea?
The code of my attachment.rb is:
class Attachment < ActiveRecord::Base
belongs_to :article
has_attached_file :url, :s3_protocol => :https ,
styles: {
medium: "300x300>", thumb: "100x100>", big: "1200x1200>", normal: "600x600>"
}
validates_attachment_content_type :url, content_type: /\Aimage|\Avideo\/.*\Z/
validates_attachment :url, content_type: { content_type: ["image/jpeg", "image/gif", "image/png", "video/mp4"] }
end
But as it is, it's not storing videos on the S3. I get the following in the terminal
Command :: file -b --mime '/var/folders/v_/pf2bsxnj1y37ccd2pjksv7z80000gn/T/f3e2afc957bb9fb2aa3e77e69359c48920160131-13311-pyeez1.mp4'
Command :: identify -format '%wx%h,%[exif:orientation]' '/var/folders/v_/pf2bsxnj1y37ccd2pjksv7z80000gn/T/8dc7385648e2164764b72fda6fd9099a20160131-13311-1l40ccn.mp4[0]' 2>/dev/null
[paperclip] An error was received while processing: #<Paperclip::Errors::NotIdentifiedByImageMagickError: Paperclip::Errors::NotIdentifiedByImageMagickError>
Command :: identify -format '%wx%h,%[exif:orientation]' '/var/folders/v_/pf2bsxnj1y37ccd2pjksv7z80000gn/T/8dc7385648e2164764b72fda6fd9099a20160131-13311-1l40ccn.mp4[0]' 2>/dev/null
[paperclip] An error was received while processing: #<Paperclip::Errors::NotIdentifiedByImageMagickError: Paperclip::Errors::NotIdentifiedByImageMagickError>
Command :: identify -format '%wx%h,%[exif:orientation]' '/var/folders/v_/pf2bsxnj1y37ccd2pjksv7z80000gn/T/8dc7385648e2164764b72fda6fd9099a20160131-13311-1l40ccn.mp4[0]' 2>/dev/null
[paperclip] An error was received while processing: #<Paperclip::Errors::NotIdentifiedByImageMagickError: Paperclip::Errors::NotIdentifiedByImageMagickError>
Command :: identify -format '%wx%h,%[exif:orientation]' '/var/folders/v_/pf2bsxnj1y37ccd2pjksv7z80000gn/T/8dc7385648e2164764b72fda6fd9099a20160131-13311-1l40ccn.mp4[0]' 2>/dev/null
[paperclip] An error was received while processing: #<Paperclip::Errors::NotIdentifiedByImageMagickError: Paperclip::Errors::NotIdentifiedByImageMagickError>
Command :: file -b --mime '/var/folders/v_/pf2bsxnj1y37ccd2pjksv7z80000gn/T/f3e2afc957bb9fb2aa3e77e69359c48920160131-13311-kvb5nr.mp4'
The second question is since I'm using AngularJS for the frontend, can I just take advantage of HTML <video> tag to render the video to the user?
Looks like the issue is that ImageMagick is trying to transcode the video, which it cannot.
The way to handle transcoding of videos within Paperclip is to use the paperclip-av-transcoder gem (formerly paperclip-ffmpeg). I only have experience with the latter:
#app/models/attachment.rb
class Attachment < ActiveRecord::Base
has_attached_file :url, :s3_protocol => :https ,
styles: lambda { |a| a.instance.is_image? ? medium: "300x300>", thumb: "100x100>", big: "1200x1200>", normal: "600x600>" } : {:thumb => { :geometry => "100x100#", :format => 'jpg', :time => 10}, :medium => { :geometry => "300x300#", :format => 'jpg', :time => 10}}}, processors: [:transcoder]
validates_attachment :url,
content_type: ['video/mp4'],
message: "Sorry, right now we only support MP4 video",
if: :is_video?
validates_attachment :url,
content_type: ['image/png', 'image/jpeg', 'image/jpg', 'image/gif'],
message: "Different error message",
if: :is_image?
private
def is_video?
url.instance.attachment_content_type =~ %r(video)
end
def is_image?
url.instance.attachment_content_type =~ %r(image)
end
end
Our old code & ref

Store thumb image to specific directory in paperclip gem

Here is the code
has_attached_file :image,
:path => ":rails_root/public/images/:id/:filename",
:url => "/images/:id/:filename",
:styles => { :small => "300x168>", :large => "1000x560>" }
Here is my console log
Command :: PATH=/opt/imagemagick-6.9/bin:$PATH; file -b --mime '/tmp/2251fc5821941d6bd28b2ee3cb25bf7620150617-13080-1gg7ekt.png'
Command :: PATH=/opt/imagemagick-6.9/bin:$PATH; identify -format '%wx%h,%[exif:orientation]' '/tmp/2251fc5821941d6bd28b2ee3cb25bf7620150617-13080-197v1bm.png[0]' 2>/dev/null
Command :: PATH=/opt/imagemagick-6.9/bin:$PATH; identify -format %m '/tmp/2251fc5821941d6bd28b2ee3cb25bf7620150617-13080-197v1bm.png[0]'
Command :: PATH=/opt/imagemagick-6.9/bin:$PATH; convert '/tmp/2251fc5821941d6bd28b2ee3cb25bf7620150617-13080-197v1bm.png[0]' -auto-orient -resize "300x168>" '/tmp/2251fc5821941d6bd28b2ee3cb25bf7620150617-13080-197v1bm20150617-13080-8q41x9'
Command :: PATH=/opt/imagemagick-6.9/bin:$PATH; file -b --mime '/tmp/2251fc5821941d6bd28b2ee3cb25bf7620150617-13080-197v1bm20150617-13080-8q41x9'
Command :: PATH=/opt/imagemagick-6.9/bin:$PATH; identify -format '%wx%h,%[exif:orientation]' '/tmp/2251fc5821941d6bd28b2ee3cb25bf7620150617-13080-197v1bm.png[0]' 2>/dev/null
Command :: PATH=/opt/imagemagick-6.9/bin:$PATH; identify -format %m '/tmp/2251fc5821941d6bd28b2ee3cb25bf7620150617-13080-197v1bm.png[0]'
Command :: PATH=/opt/imagemagick-6.9/bin:$PATH; convert '/tmp/2251fc5821941d6bd28b2ee3cb25bf7620150617-13080-197v1bm.png[0]' -auto-orient -resize "1000x560>" '/tmp/2251fc5821941d6bd28b2ee3cb25bf7620150617-13080-197v1bm20150617-13080-q57vxf'
Command :: PATH=/opt/imagemagick-6.9/bin:$PATH; file -b --mime '/tmp/2251fc5821941d6bd28b2ee3cb25bf7620150617-13080-197v1bm20150617-13080-q57vxf'
Command :: PATH=/opt/imagemagick-6.9/bin:$PATH; file -b --mime '/tmp/2251fc5821941d6bd28b2ee3cb25bf7620150617-13080-1o3we23.png'
I need to store small,large and original image to my project public directory but it store only the original
You can use :styles of paperclip gem in your model. Like,
has_attached_file :photo,
:styles => {
:thumb=> "100x100#",
:small => "150x150>",
:medium => "300x300>",
:large => "400x400>" }
And your photo url is going to be as follows : /public/photos/(event#)/(size_name)/image_name
And you have to install ImageMagick and rb-magick ports to get this going.
For more details you can refer this links Upload Image using Paperclip gem
Check that your image magick installed correctly or not as resizing is depends on image magick.
to refresh all of your defined styles in one go (:thumb, :small, :medium from the above example)
rake paperclip:refresh CLASS=Modelname
and to refresh only missing styles:
a list of styles will be defined or updated in a file “/public/system/paperclip_attachments.yml”
rake paperclip:refresh:missing_styles
Additionally, if you want to only reprocess a single style you may do so like:
users_to_reprocess.each do |user|
user.image.reprocess! :small
end

paperclip not displaying medium or thumb in rails 3.1

I'm using paperclip with Rails 3.1. When I add the image, it shows me the original size but doesn't show me thumb or medium sizes:
Here is what I have in my view:
<%= image_tag #image.avatar.url(:thumb) %>
<%= image_tag #image.avatar.url(:medium) %>
image.rb
has_attached_file :avatar, :whiny => false, :styles => { :medium => "300x300>", :thumb => "100x100>" }
UPDATE:
Here is the error I'm getting with :whiny => true
Command :: identify -format %wx%h '/var/folders/54/txjcl9l130j6dq73r37hf2c00000gn/T/stream20111213-9180-1plu1me.png[0]'
[paperclip] An error was received while processing: #
Command :: identify -format %wx%h '/var/folders/54/txjcl9l130j6dq73r37hf2c00000gn/T/stream20111213-9180-1plu1me.png[0]'
[paperclip] An error was received while processing: #
Rendered images/new.html.erb within layouts/application (4.0ms)
First, make sure that Image Magick is installed.
To see if its installed properly, go to a terminal session and type which convert. You should see a path to the executable.
Once that is done, you may need to add the path to your environment.rb file. For example, my convert is located at /usr/local/bin/convert. Now I've seen two different ways of setting your path for paperclip, try one or the other and see what works.
# specifically set the paperclip path
Paperclip.options[:command_path] = '/usr/local/bin'
# set the path in general, might not be necessary
ENV['PATH'] = '/usr/local/bin:' + ENV['PATH']

rails routes using picnik with paperclip

I've been trying to get picnik to work with paperclip so I can resize and touch up images, however have had some difficulty so far.
I'm a bit confused over the routing, as I get an error:
Started POST "/products/3/photos/4" for 208.88.21.57 at Fri Dec 10 14:44:59 -0800 2010
ActionController::RoutingError (No route matches "/products/3/photos/4"):
This is when I try to pass the file back from picnik, however simply updating the image title on the same record using the exact same path seems to work fine and uses the exact same routing as above:
Started POST "/products/3/photos/4" for 69.149.172.21 at Fri Dec 10 14:52:29 -0800 2010
Processing by PhotosController#update as HTML
Parameters: {"photo"=>{"title"=>"Front"}, "commit"=>"Update Photo", "product_id"=>"3", "authenticity_token"=>"uZ3dV3BCSm7GvP39U51KCClx2P8gIWktyki/3rnpOIM=", "utf8"=>"\342\234\223", "id"=>"4"}
[paperclip] Saving attachments.
Redirected to http://leatherarts.heroku.com/products/3
Completed 302 Found in 17ms
What am I missing?
I ignored the authenticity token in the controller for the update action... btw
Picnik takes a basic params to submit back to by post, my line looks like this:
<%= link_to "Edit or Crop", "http://www.picnik.com/service/?_import=img&img=#{#photo.data.url(:original)}&_export=#{url_for(product_photo_url(#product,#photo))}&_export_field=photos_attributes&_export_title=SaveIt&_apikey=617c5c06600b6c21ebf0bc91eafbbae5" %>
Photo Model
has_attached_file :data,
:storage => 's3',
:s3_credentials => "#{RAILS_ROOT}/config/s3_credentials.yml",
:bucket => 'leatherarts.com',
:s3_host_alias => 'leatherarts.com.s3.amazonaws.com',
:url => ':s3_alias_url',
:path => "images/products/:product_id/:style/:basename.:extension",
:styles => { :thumb => "60x60#", :small => "200x200>", :medium => "400x400>", :large => "1000x1000>" },
:default_style => :original,
:default_url => 'http://leatherarts.com.s3.amazonaws.com/images/records/m1.png',
:s3_headers => { 'Expires' => 2.months.from_now.httpdate }
validates_attachment_presence :data
validates_attachment_size :data, :less_than => 10.megabytes
validates_attachment_content_type :data, :content_type => ['image/jpeg','image/gif','image/png']
UPDATE:
I got past the first problem with a specified PUT in a new route:
match 'products/:product_id/photos/:id/picnik' => 'photos#picnik', :as => :picnik
but still can't quite get it to all fall together. It seems to work and save, but it never saves the updated image.
I added this action in my photo controller
def picnik
#product = Product.find(params[:product_id])
#photo = Photo.find(params[:id])
#photo.data(params[:data])
if #photo.save
flash[:notice] = "Successfully updated photo."
redirect_to product_path(#product)
else
render :action => 'edit'
end
end
And according to the log it seems to do what it should:
Started POST "/products/10/photos/25/picnik" for 208.88.21.59 at Sat Dec 11 08:09:32 -0800 2010
Processing by PhotosController#picnik as HTML
Parameters: {"data"=>#<File:/home/slugs/372051_88c7fa8_e87f-144ddfc3-a58b-4233-939c-2131aa001145/mnt/tmp/RackMultipart20101211-7501-1tdkwuq-0>, "product_id"=>"10", "id"=>"25"}
[paperclip] identify -format %wx%h '/home/slugs/372051_88c7fa8_e87f-144ddfc3-a58b-4233-939c-2131aa001145/mnt/tmp/paperclip-reprocess20101211-7501-1fo13g4-0[0]' 2>/dev/null
[paperclip] convert '/home/slugs/372051_88c7fa8_e87f-144ddfc3-a58b-4233-939c-2131aa001145/mnt/tmp/paperclip-reprocess20101211-7501-1fo13g4-0[0]' -resize "x60" -crop "60x60+15+0" +repage '/home/slugs/372051_88c7fa8_e87f-144ddfc3-a58b-4233-939c-2131aa001145/mnt/tmp/paperclip-reprocess20101211-7501-1fo13g4-020101211-7501-42lphg-0' 2>/dev/null
[paperclip] identify -format %wx%h '/home/slugs/372051_88c7fa8_e87f-144ddfc3-a58b-4233-939c-2131aa001145/mnt/tmp/paperclip-reprocess20101211-7501-1fo13g4-0[0]' 2>/dev/null
[paperclip] convert '/home/slugs/372051_88c7fa8_e87f-144ddfc3-a58b-4233-939c-2131aa001145/mnt/tmp/paperclip-reprocess20101211-7501-1fo13g4-0[0]' -resize "1000x1000>" '/home/slugs/372051_88c7fa8_e87f-144ddfc3-a58b-4233-939c-2131aa001145/mnt/tmp/paperclip-reprocess20101211-7501-1fo13g4-020101211-7501-1nskgrl-0' 2>/dev/null
[paperclip] identify -format %wx%h '/home/slugs/372051_88c7fa8_e87f-144ddfc3-a58b-4233-939c-2131aa001145/mnt/tmp/paperclip-reprocess20101211-7501-1fo13g4-0[0]' 2>/dev/null
[paperclip] convert '/home/slugs/372051_88c7fa8_e87f-144ddfc3-a58b-4233-939c-2131aa001145/mnt/tmp/paperclip-reprocess20101211-7501-1fo13g4-0[0]' -resize "400x400>" '/home/slugs/372051_88c7fa8_e87f-144ddfc3-a58b-4233-939c-2131aa001145/mnt/tmp/paperclip-reprocess20101211-7501-1fo13g4-020101211-7501-fpe5rc-0' 2>/dev/null
[paperclip] identify -format %wx%h '/home/slugs/372051_88c7fa8_e87f-144ddfc3-a58b-4233-939c-2131aa001145/mnt/tmp/paperclip-reprocess20101211-7501-1fo13g4-0[0]' 2>/dev/null
[paperclip] convert '/home/slugs/372051_88c7fa8_e87f-144ddfc3-a58b-4233-939c-2131aa001145/mnt/tmp/paperclip-reprocess20101211-7501-1fo13g4-0[0]' -resize "200x200>" '/home/slugs/372051_88c7fa8_e87f-144ddfc3-a58b-4233-939c-2131aa001145/mnt/tmp/paperclip-reprocess20101211-7501-1fo13g4-020101211-7501-v5e99x-0' 2>/dev/null
[paperclip] saving images/products/10/original/DSC_0212.JPG
[paperclip] saving images/products/10/etsy/DSC_0212.JPG
[paperclip] saving images/products/10/thumb/DSC_0212.JPG
[paperclip] saving images/products/10/medium/DSC_0212.JPG
[paperclip] saving images/products/10/small/DSC_0212.JPG
[paperclip] Saving attachments.
Redirected to http://leatherarts.heroku.com/products/10
Completed 302 Found in 1632ms
But it's always the same image as before, with no new adjustments from picnik? I thought maybe it was the S3 Caching, but I created a new size category and it created it with the old image just the same.

Resources