I am pulling my hair out here... I have no idea why this isn't working.
I am using ruby 1.8.7, rails 3.0.19, paperclip 2.7.4.
My model:
has_attached_file :photo, :styles => {
:logo => "60x20",
:widget => "60x40",
:thumb=> "100x100",
:small => "150x150>" },
:url => "/images/companies/:id/:style/:basename.:extension",
:path => ":rails_root/public/images/companies/:id/:style/:basename.:extension",
:default_url => "/images/bb_noimage.png"
#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','image/jpg']
In views:
<%= image_tag "#{get_image_url(company.id,company.photo_file_name,"small")}"%>
The problem is some folders will have a "large" and "thumb" size but will not have a "small" and "logo" size - I am revisiting this site after a long time of having not used it. I want the missing styles to be generated. I tried these commands and the first shows no error, but the second shows the error below. Niether generate the needed thumbnails. Thank you for your help!
bundle exec rake paperclip:refresh:thumbnails CLASS=Company
bundle exec rake paperclip:refresh:missing_styles --trace
** Execute paperclip:refresh:thumbnails
rake aborted!
No such file or directory - /Users/q/Sites/baiabase-old/public/system/paperclip_attachments.yml
/Users/q/.rvm/gems/ruby-1.8.7-p302#baia-old/gems/paperclip-2.7.4/lib/paperclip/missing_attachment_styles.rb:25:in `initialize'
add to your model
attr_accessible :photo, :photo_file_name
has_attached_file :photo, :styles => {.....
....your code...
and in views
<%= image_tag #company.photo.url(:small) %>
And more to you as a gift, it is
For photos of the original 512x512 pixels will be better, will take up less space on your hard drive on the server
add style :original => "512x512",
all attached photo converted maximum to this resolution, that save space on your hard drive.
:less_than => 3.megabytes change to :less_than => 5.megabytes
If the user tries to attach a photo larger than 3 MB then it will not do it, change it to 5 MB
the user can add photos which has a resolution of 3000 x 3000 or more (<= 5 mb) but it was all smooth will be converted to 512 x 512 pixels which weight will be no more than 20 KB.
And if you want to convert all attached photos to jpg (format) try this :thumb => {:geometry => '100x100#', :format => :jpg},
and attentively with the Aspect ratio 4:3 '100x100#' and Aspect ratio 16:9 '100x100>'.
Related
i need any solution for reducing image size
I am using paperclip
has_attached_file :image, :styles => { :small =>{ :geometry =>"200 x 123>"}}
For example i have original image 1 Mb and after some magic i want image 300 Kb
and then upload it on aws
You can use the convert_options
has_attached_file :image,
:convert_options => { :thumb => '-quality 50' }
or you can try this one
has_attached_file :image => { :quality => :better }
Refer: Paperclip doc
Take a look at this
https://github.com/janfoeh/paperclip-optimizer
It's a gem made for image optimization.
If you need a better optimization, use Google PageSpeed module for apache or Nginx !
When I copy a paperclip attachment it applies the default cropping defined in the style and ignores the cropper I have installed for cropping on the site via user input (CropperJs). What I need is just a raw copy of the image as it was cropped on the source image. I solve this by bluntly copying the file right now, but is there a better way?
has_attached_file :avatar,
:name => 'avatar',
:styles => {
:cropped => {
:geometry => "55x55#",
:processors => [:cropper]
},
:large => "600x600>"
}
I'm using paperclip gem for uploading and resizing images. This setup works fine. I'm able to display the uploaded images. The problem comes when I try to resize the uploaded image.
Here is snippet from the model file
has_attached_file :photo,
:size => {:small => "150x150>"}
When I try to upload the image I get this error.
Photo /var/folders/gm/gm-SegRMHuOkSlYtTMkO8U+++TI/-Tmp-/file.jpg is not recognized by the 'identify' command.
I'm sure that the file is jpg. Here is the output of the file command
file.jpg: JPEG image data, JFIF standard 1.01, comment: "CREATOR: gd-jpeg v1.0 (using IJ"
I'm not sure but in our application we do the same thing and it works. Our code looks like this:
has_attached_file :image,
:styles => {:small => "280x173#", :medium => "635x393#"},
:convert_options => {:all => "-quality 80"},#,
:default_style => :medium,
:default_url => "/images/study/nophoto.jpg"
validates_attachment_size :image, :less_than => 10.megabyte
validates_attachment_content_type :image, :content_type => ['image/gif', 'image/png', 'image/x-png', 'image/jpeg', 'image/pjpeg', 'image/jpg']
The difference I see, is that you might have to provide convert_options to be able to resize.
Have you tried any other jpg file, maybe with a simpler path also?
This is the code in my model:
has_attached_file :photo,
:styles => {
:tiny => "25x25#",
:thumbnail => "50x50#",
:small => "150x150>",
:medium => "300x300>" },
:default_url => "/images/default_:style.jpg"
I run this command:
rake paperclip:refresh:thumbnails CLASS=Photo
and I get this error:
rake aborted!
uninitialized constant Photo
What going on? How can I fix this?
Obviously it doesn't know your model Photo. Try a command "require", e.g.
require "lib/photo"
or whatever your model path is.
class User < ActiveRecord::Base
has_attached_file :photo, :styles => { :square => "100%", :large => "100%" },
:convert_options => {
:square => "-auto-orient -geometry 70X70#",
:large => "-auto-orient -geometry X300" },
:storage => :s3,
:s3_credentials => "#{RAILS_ROOT}/config/s3.yml",
:path => ":attachment/:id/:style.:extension",
:bucket => 'mybucket'
validates_attachment_size :photo,
:less_than => 5.megabyte
end
Works great on local machine, but gives me an error on Heroku: There was an error processing the thumbnail for stream.20143
The thing is I want to auto-orient photos before resizing, so they resized properly.
The only working variant now(thanks to jonnii) is resizing without auto-orient:
...
as_attached_file :photo, :styles => { :square => "70X70#", :large => "X300" },
:storage => :s3,
:s3_credentials => "#{RAILS_ROOT}/config/s3.yml",
:path => ":attachment/:id/:style.:extension",
:bucket => 'mybucket'
...
How to pass additional convert options to paperclip on Heroku?
UPD
I discover, the trouble in "-auto-orient" option. It seems like this option is broken in version of ImageMagick used by Heroku. I created custom paperclip image processor inherited from paperclip's standard thumbnail:
module Paperclip
class Ao < Thumbnail
def transformation_command
super + " -auto-orient"
end
end
end
It works perfect on local machine, but fails on Heroku.
These are the sizes I use. They all work fine on heroku:
SIZES = {
:original => "640x480>",
:thumb => "150x150#",
:mini => "60x60#",
:micro => "30x30#"
}
Make sure your gem version of paperclip is the same as heroku's. You can specify the specific gem version in your .gems file and in your environment.rb to make sure they line up.
I'm not sure exactly why your convert_options are causing problems, but if I remember correctly paperclip uses ImageScience directly and your chosen options might be incompatible with the read only heroku file system.
If this is critical and you need an answer right now I'd raise a support ticket on heroku. If you get a response make sure you post it back here!