I uploaded a missing.png to public/images/ folder. But the the missing.png not showing correctly.
The website requires images/small/missing.png
So I guest I should generate the missing.png for thumb small medium large size.
What should I do?
Update 1:
I manually create a folder public/images/small and put missing.png inside the small folder. The website shows the missing.png. But What's is the correct way to generate all size of missing.png?
Try to add this in your model:
has_attached_file :image, styles: { :small => "150x150>", medium: "300x300>", thumb: "100x100>" }, default_url: "/images/:style/missing.png"
Related
I am using paperclip for image uploading and in my model I have specified styles to store the images with various sizes, I have imagemagick installed, here are the codes
has_attached_file :image,
styles: { medium: '300x300>', thumb: '40x40>' },
path: 'images/:id/image/:basename.:extension',
default_url: 'default.png'
validates_attachment :image, content_type: { content_type: %w[image/jpeg image/png] }
It doesn't seems to store images with these specified styles, It only stores image with default style. Do I miss anything here?. Thanks in advance
I did a mistake by overriding the paperclip default path without :style specified. So it stores only the default size. The processed image (by ImageMagick) does not store as I didn't mention at override path.
I used the paperclip gem to upload images onto my app. Now I'm trying to deploy to Heroku and want to use Cloudinary to host the images. I followed the documentation and added my cloudinary.yml file into my config directory. Even locally when I add this my images disappear
this works locally:
has_attached_file :avatar, styles: { medium: "300x300", thumb: "100x100" }
Adding the commands for cloudinary makes all my images disappear:
has_attached_file :avatar, styles: { medium: "300x300", thumb: "100x100" },:storage => :cloudinary,
:path => ':id/:style/:filename'
If I try to push to heroku it also doesn't work.
I'm using paperclip for uploading profile pictures. When someone does not upload an image I want a default image to be assigned to the user instead.
I'm using this line of code:
has_attached_file :avatar,
styles: { medium: "300x300>", thumb: "100x100>" },
default_url: "assets/images/:style/male.jpg"
But my browser inspector gives me this error:
http://localhost:3000/assets/images/original/male.jpg 404 (Not Found)
I've tried writing:
default_url: "assets/images/:style/male.jpg"
default_url: "images/:style/male.jpg"
default_url: ":style/male.jpg"
default_url: "male.jpg"
default_url: "assets/images/male.jpg"
The image lies in the following places:
/assets/images/male.jpg
/assets/images/medium/male.jpg
/assets/images/thumb/male.jpg
/assets/images/original/male.jpg
Ommit the /images/ instead do this /assets/male.jpg or /assets/original/male.jpg
Hope that help you out.
I'm using paperclip for image storage, and i have a problem. When the file is uploaded, paperclip generates two files, a processed image with a watermark and the original file, in this case the image files are in public folder, now the question is, can i restric the url in case the user enter into it like:
localhost:3000/files/photos/image_processeds/57308cd52cb1be0846e4be9f/original/image.png
If the user enter into the link, it will be forbidden.
This is my paperclip config
has_mongoid_attached_file :image_original,
:url => "/files/:class/:attachment/:id/:style/:basename.:extension",
:path => ":rails_root/public/files/:class/:attachment/:id/:style/:basename.:extension"
and
has_mongoid_attached_file :image_processed,
processors: [:watermark],
styles: {
thumb: ['150x150', :jpg],
small: ['350x300', :jpg],
medium: ['550x500', :jpg],
original: {geometry: '60%',watermark_path: "#{Rails.root}/public/images/logo.gif", position: "Center"}
},
:url => "/files/:class/:attachment/:id/:style/:basename.:extension",
:path => ":rails_root/public/files/:class/:attachment/:id/:style/:basename.:extension"
Theres is a way to do it or maybe find a better approach for that?
The original/image.png should be watermarked I guess.
I mean the version without watermark should not exist after processing.
Did you check it?
Solved, a reliable solution is save a copy of the original image into the database and grant access to it only when they purchase the photo, otherwise they only can see the copies with watermark :)
I have was seeing several discussions (on stackoverflow here and here, and as a bug on paperclip here) around the best way to tell the default_url of images using Paperclip and Rails so that they work fine in production with the asset pipeline. All solutions appear quite complicate.
Is there anything wrong in putting the default images in the public/ directory of the Rails app? Anything I need to worry down the line or that I am missing?
If I put images in the public/ directory and access them with the code below all appears to work correctly.
has_attached_file :image,
styles: {original: "1000x1000", medium: "530x530#", thumb: "300x300#"},
default_url: "/default-avatar_:style.png"
I generally, by convention alone include the missing styles images in the assets directory. You don't need any extra coding or complex mechanisms to have paperclip utilize them.
#Images within assets:
/app/assets/images/default-avatar_original.png
default-avatar_medium.png
default-avatar_thumb.png
# paperclip config in /app/models/user.rb
has_attached_file :image, :styles => {:original => ["1000x1000", :png],
:medium => ["530x530#", :png],
:thumb => ["300x300#", :png] },
:default_url => "/assets/default-avatar_:style.png"
Note that when specifying default_url, you exclude the /image/ directory.