I'm using ruby 1.9.2, rails 3.0.8, paperclip 2.3.11.
I installed imagemagick some time ago using macports. To find the version I used:
convert -version
Version: ImageMagick 6.5.6-1 2009-10-01 Q8 OpenMP http://www.imagemagick.org
Copyright: Copyright (C) 1999-2009 ImageMagick Studio LLC
In my model I'm setting:
class Sketch < ActiveRecord::Base
has_attached_file :image, :style => {:ipad => "786x1024>", :iphone => "320x480>"}, :default_style => :ipad, :whiny_thumbnails => true
has_many :comments
end
When I upload my image, the original size is uploaded but the thumbnails are never created. Even though I set whiny_thumbnails to true, I don't see any error output.
What else do I need to do?
Ultimately I want to deploy on Heroku, so I prefer not to use any configuration methods that are not compatible with Heroku.
The key for is :styles not :style.
has_attached_file :image, :styles => {:ipad => "786x1024>", :iphone => "320x480>"}, :default_style => :ipad, :whiny_thumbnails => true
^
Related
I am able to upload videos locally. The videos are processed using paperclip and all the meta data is saved correctly, as well. When I tried to upload a video using our remote server, I received the error:
Av::UnableToDetect (Unable to detect any supported library)
I have installed ffmpeg using LinuxBrew. It says everything is installed correctly (checking which brew and which ffmpeg, as well as checking if the gem is appropriately installed).
When I have styling in my model for the video (which is what enables the meta information to be stored and to have control over how the video is uploaded) it doesn't work remotely.
has_attached_file :video, path: "/posts/:id/:style.:extension",
:styles => {
:medium => { :geometry => "493x877", :format => 'flv' },
:thumb => { :geometry => "100x100#", :format => 'jpg', :time => 10 },
# :mobile => {:geometry => "640X480", :format => 'mp4', :streaming => true}
}, :processors => [:transcoder]
However, when I remove this from my model and have:
has_attached_file :video, path: "/posts/:id/:style.:extension"
The video is uploaded to S3 (without the data or styling that I need).
Any help would be greatly appreciated. I think AV is having trouble finding ffmpeg but I am not sure why or how to go about fixing it. Thanks in advance for any advice.
I had the same issue just this past week - Try this!
Video model:
has_attached_file :video, styles: {
:medium => {
:geometry => "640x480",
:format => 'mp4'
},
:thumb => { :geometry => "160x120", :format => 'jpeg', :time => 10}
}, :processors => [:transcoder]
validates_attachment_content_type :video, content_type: /\Avideo\/.*\Z/
Make sure you already bundled:
gem 'paperclip', '~> 4.3.1'
gem 'aws-sdk', '< 2.0'
gem 'paperclip-av-transcoder'
gem "paperclip-ffmpeg", "~> 1.2.0"
Run the paperclip migration:
rails g paperclip model video
Be sure to add in post_controller.rb:
private
def bscenes_params
params.require(:post).permit(:video)
end
Upload form:
<%= f.file_field :video %>
Show page:
<%= video_tag bscene.video.url(:medium), controls: true, style: "max-width: 100%;" %>
At this point you should get this error:
Av::UnableToDetect (Unable to detect any supported library):
For Mac
Go to your terminal and type in:
brew options ffmpeg
Then run the following to install ffmpeg:
For older versions of brew recipe:
brew install ffmpeg --with-fdk-aac --with-ffplay --with-freetype --with-frei0r --with-libas
For newer versions of brew recipe:
brew install ffmpeg --with-fdk-aac --with-sdl2 --with-freetype --with-frei0r --with-libass
For Linux Mint / Ubuntu / Debian based Linux
Open a terminal (Ctrl + Alt + T) and execute following commands one by one to install ffmpeg.
sudo add-apt-repository ppa:mc3man/trusty-media
sudo apt-get update
sudo apt-get dist-upgrade
sudo apt-get install ffmpeg
At this point Video uploads will work locally
Now for remote uploads you will need to setup https://devcenter.heroku.com/articles/buildpacks
This should now bring you to your error
Av::UnableToDetect (Unable to detect any supported library)
You will need to create a Procfile in the root of your app directory more information about Procfile here: https://devcenter.heroku.com/articles/procfile
touch Procfile
Hope this helps!
I got this error in airbrake at production: (I just uploaded a version with an upgrade of both rails and ruby, to 1.9.3 and 3.2)
Cocaine::ExitStatusError: Command 'convert /tmp/photo (1)20130424-3742-dohg6e.JPG -auto-orient /tmp/20130424-3742-eiksvr' returned 2. Expected 0 Here is the command output:
my paperclip code:
has_attached_file :photo,
:styles => {:original => "1024x1024>", :large => '800x600>', :thumb => '120x72#'},
:convert_options => {:original => '-strip -quality 90', :large => '-strip -quality 90', :thumb => '-strip'},
:processors => [:auto_orient, :thumbnail],
:url => "/system/statuses/:id_partition/:style.:extension",
:path => ":rails_root/public/system/:id_partition/:style.:extension"
what does this error mean? and how can i handle it?
thanks
I'm no entirely sure. But it seems that your production server doesn't have the ImageMagick library installed properly.
cocaine is a library for executing commnad tools.. I believe that it is trying to call some imagemagick command and returning somekind of error
Paperclip rescue's any Cocaine error, including things like Segmentation Faults in ImageMagick. It returns a '' i.e. an empty string. Line 27 of geometry dector factory.
I'm migrating from Active Record to Mongoid, and this paperclip stuff used to work fine. I'm using Ubuntu 12.04.
I've got this code in my mongoid document:
has_mongoid_attached_file :photo,
:styles => {
:thumb => "60x60",
:small => "100x100",
:medium => "300x200",
:large => "600x400"
},
:storage => :s3,
:s3_credentials => "#{Rails.root}/config/s3.yml",
:path => "#{Rails.env}/merc:attachment/:id/:style.:extension",
:url => ":s3_alias_url",
:bucket => '%^&*&^'
I have the rmagick gem installed and the command_path pointing to where the various imagemagick commands are -> '/usr/bin'.
I'm using Unicorn as my webserver, and I have verified that identiy and convert are available by putting this in my view:
<%= `which convert` %>
<%= `echo $PATH` %>
But alas, when I try to upload the image I get :
Photo /tmp/qdoba20121005-27609-1m3kq9c.jpg is not recognized by the
'identify' command. Photo /tmp/qdoba20121005-27609-1m3kq9c.jpg is not
recognized by the 'identify' command. Photo
/tmp/qdoba20121005-27609-1m3kq9c.jpg is not recognized by the
'identify' command. Photo /tmp/qdoba20121005-27609-1m3kq9c.jpg is
not recognized by the 'identify' command.
Seemingly one for every one of the styles I have defined.
I've confirmed that the file exists, and I can run identify on the file from the commandline.
Any help will be appreciated. Thanks!
There is a recent update to the Cocaine gem that is breaking the imagemagick filenames for a lot of people - check it out because rolling back Cocaine to the previous version may help.
See here:
https://github.com/thoughtbot/paperclip/issues/1038
I've set up paperclip in rails and everything is working hunky-dory (i actually had to google that...:).
I've noticed however that Page Speed tells me I could losslessly compress my thumbnail and large images (the ones that paperclip produces) further. Is there an option I can put into my model which does this? I've noticed that mod_deflate doesn't compress images (I'm using Firefox).
You can add compression to paperclip processing using the paperclip-compression gem.
In your Gemfile:
gem "paperclip-compression", "~> 0.1.1"
(of course run bundle install)
In your model:
has_attached_file :avatar,
:styles => { :medium => "300x300>", :thumb => "100x100>" },
:processors => [:thumbnail, :compression]
"jpegtran works by rearranging the compressed data (DCT coefficients), without ever fully decoding the image. Therefore, its transformations are lossless"
Note: if you are running on heroku, you'll need jpegtran, and optipng binaries added to your application. Here's a good article on running binaries on heroku.
You should do your own testing on various JPEG compression levels but I've noticed that I can bump ImageMagicks quality setting down to 75 and still not see any noticeable difference - with about a 30-40% file size savings.
My model looks like:
has_attached_file :photo,
:styles => {
:"185x138" => {
:geometry => "185x138>"
} },
:convert_options => {
:all => "-auto-orient",
:"185x138" => "-quality 75",
-quality 75 is for ImageMagick. If you're using a different processor you will need to adjust accordingly.
What about FFMPEG or AVCONV?
sudo apt-get install ffmpeg/avconv
= initializer
Paperclip.options[:command_path] = "/usr/bin/" # see `which ffmpeg`
= Modal
after_save :compress_with_ffmpeg
def compress_with_ffmpeg
[:thumb, :original, :medium].each do |type|
img_path = self.avtar.path(type)
Paperclip.run("ffmpeg", " -i #{img_path} #{img_path}")
end
end
I installed the paperclip plugin and was able to use it locally. When I configured it to work with amazon S3 I keep getting the NoSuchBucket (The specified bucket does not exist) error. Paperclip documentation states that the bucket will be created if it doesn't exist but clearly
something is going wrong in my case.
I first insalled aws-s3 gem (v0.6.2)
then also installed right_aws gem (v1.9.0)
both have corresponding
config.gem "aws-s3", :lib => "aws/s3"
config.gem 'right_aws', :version => '1.9.0'
lines in environment.rb file
The code for the image.rb file with paperclip is as follows:
class Image < ActiveRecord::Base
belongs_to :work
has_attached_file :photo, :styles => {:big => "612x1224>", :small => "180X360>", :thumb => "36x36#"},
:storage => 's3',
:s3_credentials => YAML.load_file("#{RAILS_ROOT}/config/s3.yml")[RAILS_ENV],
:path => ":attachment/:id/:style/:basename.:extension",
:bucket => 'my-unique-image-bucket'
attr_protected :photo_file_name, :photo_content_type, :photo_size
validates_attachment_presence :photo
validates_attachment_size :photo, :less_than => 3.megabytes
validates_attachment_content_type :photo, :content_type => ['image/jpeg', 'image/png', 'image/gif']
end
I'm not entirely sure this is it, but your loading of the s3_credentials is different than what I'm using on my production sites.
My config line is:
:s3_credentials => "#{RAILS_ROOT}/config/s3.yml"
Instead of
:s3_credentials => YAML.load_file("#{RAILS_ROOT}/config/s3.yml")[RAILS_ENV]
it should create but the bucket but this was a bug at one point :
http://groups.google.com/group/paperclip-plugin/browse_thread/thread/42f148cee71a0477
i recently had this problem and it turned out to be the servers time was hugely off and s3 wouldnt allow any updates "that far in the future" or similar but the rails error was NoSuchBucket...confusing
..
I have installed the s3fox plugin for firefox and created the bucket with the plugin. Now Paperclip works fine with S3 as the bucket identified is already created.
But I am still curious about paperclip's inability to create new buckets with the code above.
In case anyone winds up here via google: I saw this same error when I mistakenly switched the order of the 2nd and 3rd parameters I was passing to AWS::S3::S3Object.store.
It's not your case, but AWS doesn't allow upper case letters in bucket name and paperclip doesn't check that, failing in create_bucket.