Paperclip is not saving the original file when a style is defined - ruby-on-rails

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'>

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 missing.png not showing

In my member model I have a default url when no image is uploaded:
default_url: "/images/:style/missing.png"
in the assets/images folder I created a 'medium' folder and stored an image 'missing.png'
However, when I created a new member object and not upload an image, the webpage doesn't show the missing.png
Am I missing something?
I also tried the solution here and changed the default setting to:
default_url: "/:style/missing.png"
but that didn't work.
Help is much appreciated
You can use the below working code. It's working fine in my case.
has_attached_file :content, styles: { thumb: "120x120>", medium: "160x226" }, default_url: "/assets/noimage/:style/missing.png",
:storage => :s3,
:s3_protocol => 'https',
:s3_host_name => Settings.aws.s3.host_name,
:s3_credentials => {
:bucket => Settings.aws.s3.bucket,
:access_key_id => Settings.aws.access_key_id,
:secret_access_key => Settings.aws.secret_access_key
}

Paperclip Resize and Crop

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!

Imagehack and paperclip how to create a thumb and define path and filename?

I am trying to create a thumb with and uploaded image. I also want to resize the uploaded image to 672x378 and the thumb is should be 219x123.
The path for the thumb should be photographer/image/:id/thumb:Filename
I have installed imageshack (gem 'Rmagick') and intstalled the program on my pc.
My model:
has_attached_file :image,
:storage => :s3,
:bucket => 'mybucket',
:path => '/photographer/image/:id/:filename',
:s3_credentials => {
:access_key_id => 'mykey',
:secret_access_key => 'mykey'
}
It looks like you want to attach images to photographers. So in that case I would include this code on the photographer model.
has_attached_file :image,
:styles => { :original => "672>x378>", :thumb => "219>x123>" }, # width x height
:storage => :s3,
:bucket => "mybucket",
:path => "photographers/:id/images/:style/:basename.:extension",
:s3_credentials => {
:access_key_id => 'mykey',
:secret_access_key => 'mykey'
}
Not that the > after the size of the images will restrict the width from exceeding the value, but still keep the image in proportion. So, the image can't go larger than the height or width. You can remove those if you want.

How to pass additional convert options to paperclip on Heroku?

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!

Resources