Paperclip Resize and Crop - ruby-on-rails

I am using Paperclip with Rails4. I have the following image
Now i want to resize and Crop the image but its getting cropped and orientation of the image is getting displaced like below
:photo,
:path => ":rails_root/public/system/:attachment/:id/:style/:filename",
:url => "/system/:attachment/:id/:style/:filename",
:styles => {
:small => { :geometry => "100x100!" },
:medium => { :geometry => "500x500!"}
}

Check out ImageMagic resize docs. You probably need to use 100x100# instead of 100x100!

Related

URL issue: paperclip-av-transcoder

I am trying to implement paperclip-av-transcoder gem. I have checked everything but not able to find what I am doing wrong here. I'm writing steps which I have followed.
Added into gemfile
--> gem 'paperclip-av-transcoder'
Added into my model
--> has_attached_file :video_file, :styles => {
:medium => { :geometry => "640x480", :format => 'mp4' },
:thumb => { :geometry => "100x100#", :format => 'jpg', :time => 10 }
}, :processors => [:transcoder]
--> validates_attachment_content_type :video_file, :content_type => /\Avideo\/.*\Z/
created schema to add column name
"video_file_meta"
In my view file
video_tag(video.video_file.url, controls: true, autobuffer: true, size: "320x240")
I have checked video in public/system folder it is properly saved I am able to see that video there but I am not able to see that in my view file.
Video Url -> /system/videos/video_files/000/000/003/original/tingtong_464.mp4?1497851104
I am sharing screens to show how it looks in the browser.
Everything from my point is correct, except Paperclip requires at least one field in database - *_file_name (for you it's video_file_file_name), but you didn't added it and Paperclip can't construct url properly. Read more https://github.com/thoughtbot/paperclip#usage
Currently working model file code:
has_attached_file :video_file, :styles => {
:medium => { :geometry => "500x500", :format => 'jpg' },
:thumb => { :geometry => "100x100", :format => 'jpg' }
}, :processors => [:transcoder]
validates_attachment_content_type :video_file,
:content_type => [
"video/mp4",
"video/quicktime",
"video/3gpp",
"video/x-ms-wmv",
"video/mov",
"video/flv",
],
:message => "Sorry! We do not accept the attached file type"
I guess I am not resizing my video file in any other video format so it is working properly.

Paperclip - Using custom watermark with dynamic path

I'm trying to create a custom path using this:
has_attached_file :avatar,
:processors => [:watermark],
:styles => lambda { |attachment| {
:medium => {
:geometry => "300x300>",
:watermark_path => Customer.find(attachment.instance.customer_id).signature.path
},
:thumb => "100x100>",
}
}
This is working fine with Customer.find(attachment.instance.customer_id).signature.path with a static path to image, but in this case it is throwing an exception
Paperclip::Errors::InfiniteInterpolationError in Api::Ipad::V1::ImagesController#create
Can anyone tell how to ignore this exception ?
Usually that error comes from not explicity defining the :url and :path options for the attachment, might try setting those options and see if the interpolation error goes away.

Rails paperclip generate thumbnail from other style

I'm following the jcrop rails tutorial, but I've hit a snag. What it comes down to is the fact that paperclip is generating the thumbnail from the original file, but I need it to be generated from another style. The original file doesn't have any space between the product shot and the edge of the document. Therefore I can't crop further out. To combat that, I made another style which has white pixel padding. That's what I want to generate the thumbnail from.
# croppable is the one with the padding...it's what shows up in the crop view.
# I want :thumb to be generated from THAT style, not :original.
# When generating from :original, the crop offset/size is screwed because the dimensions of :original don't match :cropped
# and I can't crop beyond the pixel dimensions of :original.
has_attached_file :photo, :styles => {
:thumb => { :geometry => "300x300#", :format => :jpg, :processors => [:cropper] },
:general => ["150x375", :jpg],
:show => ["x425", :jpg],
:croppable => ["1200x1200>", :jpg]
},
:url => "/assets/wines/:style/:wine_name",
:path => ":rails_root/public:url",
:default_url => ":wine_default",
:default_path => ":rails_root/public:wine_default",
:default_style => :show,
:convert_options => {
:thumb => '-gravity center -rotate -30',
:croppable => '-gravity center -extent 1200x1200',
:general => '-gravity center -extent 150x375 -quality 95',
:all => '-quality 100 -antialias -flatten -background white -unsharp 0.3x0.3+5+0'
},
:processors => [:thumbnail, :compression]
I came across a processor that someone else had made online and used it for myself. Details can be found at http://pjkh.com/articles/speeding-up-thumbnail-generation-with-paperclip/ for advanced usage information.
recursive_thumbnail.rb (include in lib/paperclip_processors)
module Paperclip
class RecursiveThumbnail < Thumbnail
def initialize file, options = {}, attachment = nil
super Paperclip.io_adapters.for(attachment.styles[options[:thumbnail] || :original]), options, attachment
end
end
end
and for your model:
:styles => {
:croppable => ["1200x1200>", :jpg],
:show => ["x425", :jpg],
:general => ["150x375", :jpg],
:thumb => {
:geometry => "150x150^",
:format => :jpg,
:processors => [:recursive_thumbnail] },
:thumbnail => :croppable
}
Maybe this would help you or someone else like me who Google led to this question.
https://github.com/thoughtbot/paperclip/wiki/Thumbnail-Generation
Generating/regenerating your thumbnails
Note: regenerating only one of several defined styles as described in
some of the examples below will lead to broken paths/urls for all
other styles if you have :hash in your paperclip_defaults[:path] and
:updated_at in your paperclip_defaults[:hash_data] (and you have by
default). Don’t do this unless you really know what you’re doing.
You can (re)generate your thumbnails en masse with Paperclip’s rake
tasks. Using our example class above:
bundle exec rake paperclip:refresh:thumbnails CLASS=User

Paperclip is not saving the original file when a style is defined

I'm working to make Paperclip store a thumbnail in addition to the original image. The original image had always saved file and now I'm trying to add a thumbnail.
The problem is, once I defined the style thumbnail, the original is no longer being saved. How can I get the original to save along with the thumb?
has_mongoid_attached_file :attachment,
:storage => :s3,
:s3_credentials => "s3.yml",
:s3_protocol => 'https',
:s3_permissions => :private,
:use_timestamp => true,
:default_style => :original,
:default_url => '/images/:attachment/default_:style.png',
:path => "/:rails_env/private/:basename.:extension",
:styles => {
:thumb => "100x100#" },
:convert_options => {
:thumb => "-quality 75 -strip" }
Install Imagemagic (https://github.com/thoughtbot/paperclip) and then you can rezize your original sized photo into any size by using like this
<img src="#", size: '150x150'>

Paperclip, copy image without reprocessing it

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>"
}

Resources