KilgoreTrout
KilgoreTrout

Reputation: 73

RAILS + PaperClip - store resized image only

My model looks like:

class Photo < ApplicationRecord
  has_attached_file :image, 
                    :styles => { :small => "50x50#" },
                    :default_style => :small                   

  validates_attachment :image,
                       content_type: { content_type: ["image/jpeg",   
                                      "image/gif", "image/png"] }
end

RAILS stores the image twice: as original size, and as resized defined in :small. I would like to store only resized image.

Upvotes: 0

Views: 72

Answers (2)

KilgoreTrout
KilgoreTrout

Reputation: 73

Thank you, puneet18.

This model do the job:

class Photo < ApplicationRecord
  has_attached_file :image, 
                    :styles => { :original => "50x50#" },
                    :default_style => :original

  validates_attachment :image,
                       content_type: { content_type: ["image/jpeg", "image/gif",
                                       "image/png"] }
end

Upvotes: 0

puneet18
puneet18

Reputation: 4427

I believe that you can simply define a style for :original to have paperclip replace the original with that size.

:styles => { :original => '300x168>', :cropped_thumb => {:geometry => "50x50#", :jcrop => true}, ...}

Upvotes: 1

Related Questions