diff --git a/app/models/album.rb b/app/models/album.rb index b0a435f..84b8b2c 100644 --- a/app/models/album.rb +++ b/app/models/album.rb @@ -15,6 +15,7 @@ class Album field :order, type: Integer, default: -1 field :min_order, type: Integer, default: -1 field :resize_gravity + field :thumb_process_option, type: Integer, default: 0 # has_and_belongs_to_many :tags, :class_name => "GalleryTag" has_many :album_images, :autosave => true, :dependent => :destroy has_many :album_colors, :autosave => true, :dependent => :destroy diff --git a/app/uploaders/gallery_uploader.rb b/app/uploaders/gallery_uploader.rb index d4cb222..eaef6b3 100644 --- a/app/uploaders/gallery_uploader.rb +++ b/app/uploaders/gallery_uploader.rb @@ -13,7 +13,7 @@ class GalleryUploader < CarrierWave::Uploader::Base # Include RMagick or ImageScience support: # include CarrierWave::RMagick # include CarrierWave::ImageScience - include CarrierWave::MiniMagick + include CarrierWave::MiniMagick # Choose what kind of storage to use for this uploader: # storage :file # storage :s3 @@ -68,11 +68,11 @@ class GalleryUploader < CarrierWave::Uploader::Base end version :thumb do process :convert => 'png', :if => :transparent? - process :pad_process => [200,200] + process :thumb_process => [200, 200] end version :thumb_large do process :convert => 'png', :if => :transparent? - process :pad_process => [600,600] + process :thumb_process => [600, 600] end version :theater do process :limit_process => [1920, 1080] @@ -175,9 +175,14 @@ class GalleryUploader < CarrierWave::Uploader::Base now_album = model.album now_album.album_colors.first['color']=='transparent' rescue true end - def pad_process (w,h) + def thumb_process(w,h) now_album = model.album - resize_and_pad(w, h, (transparent? ? :transparent : now_album.album_colors.first['color']), (now_album.resize_gravity rescue 'Center')) + case now_album.thumb_process_option + when 0 + resize_and_pad(w, h, (transparent? ? :transparent : now_album.album_colors.first['color']), (now_album.resize_gravity rescue 'Center')) + when 1 + limit_process(w, h) + end end end diff --git a/app/views/admin/galleries/_form.html.erb b/app/views/admin/galleries/_form.html.erb index 2c734c5..7283f6a 100644 --- a/app/views/admin/galleries/_form.html.erb +++ b/app/views/admin/galleries/_form.html.erb @@ -59,7 +59,11 @@ input.minicolors-input{ } }) return true - }) + }); + $('#album_thumb_process_option').change(function(){ + $('.thumb_process_option').hide(); + $('.thumb_process_option'+'.'+$(this).val()).show(); + }).trigger('change'); });
@@ -76,7 +80,7 @@ input.minicolors-input{ <%= t(:tags) %>
  • - <%= t('gallery.recreate_thumb') %> + <%= t('gallery.advanced_setting') %>
  • @@ -108,43 +112,50 @@ input.minicolors-input{ <% if @album.album_colors.first.nil? %> <% @album.album_colors.new('color' => 'transparent') %> <% end %> - <%= f.fields_for :album_colors do |album_color_form| %> -
    - -
    - - <%= album_color_form.text_field :color , :class => 'input-block-level minicolors-input' %> - - - <%= t('gallery.transparent') %> - -
    -
    - - <%= album_color_form.text_field :album_card_background_color, :class => 'input-block-level minicolors-input' %> - - - <%= t('gallery.transparent') %> - -
    -
    - - <%= album_color_form.text_field :album_card_text_color, :class => 'input-block-level minicolors-input' %> - - - <%= t('gallery.transparent') %> - -
    -
    - -
    - <%= f.select :resize_gravity, [["---#{t("default")}: #{t("gallery.gravity.#{AlbumSetting::ResizeGravities[0]}")}---",nil]]+AlbumSetting::ResizeGravities.collect{|v| [t("gallery.gravity.#{v}"),v]} %> -
    -
    +
    +
    + +
    + <%= f.select :thumb_process_option, t('gallery.thumb_process_option').to_enum.with_index.collect{|v, i| [v, i]} %>
    +
    + <%= f.fields_for :album_colors do |album_color_form| %> + + +
    + + <%= album_color_form.text_field :color , :class => 'input-block-level minicolors-input' %> + + + <%= t('gallery.transparent') %> + +
    +
    + +
    + <%= f.select :resize_gravity, [["---#{t("default")}: #{t("gallery.gravity.#{AlbumSetting::ResizeGravities[0]}")}---",nil]]+AlbumSetting::ResizeGravities.collect{|v| [t("gallery.gravity.#{v}"),v]} %> +
    +
    +
    + + <%= album_color_form.text_field :album_card_background_color, :class => 'input-block-level minicolors-input' %> + + + <%= t('gallery.transparent') %> + +
    +
    + + <%= album_color_form.text_field :album_card_text_color, :class => 'input-block-level minicolors-input' %> + + + <%= t('gallery.transparent') %> + +
    <% end %> +
    diff --git a/app/views/admin/galleries/_recreate_thumb.html.erb b/app/views/admin/galleries/_recreate_thumb.html.erb index 76aac23..ef68257 100644 --- a/app/views/admin/galleries/_recreate_thumb.html.erb +++ b/app/views/admin/galleries/_recreate_thumb.html.erb @@ -4,7 +4,7 @@
    -<%= t('gallery.recreate_thumb')+':' %> +<%= t('gallery.frame_color')+':' %> diff --git a/config/locales/en.yml b/config/locales/en.yml index 93667d9..afb6350 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -2,6 +2,11 @@ en: gallery: setting: Gallery Setting + advanced_setting: Advanced Setting + thumb_process_option_trans: Thumb Process Option + thumb_process_option: + - resize and padding + - resize only inner_page_layout: Inner Page Layout card_style: Card Style grid_style: Grid Style @@ -59,7 +64,7 @@ en: progressbar: 'Progress bar' error: 'Recreate thumb failed, please contact service agent or try again later' 'sure?': 'Are yoy sure to apply? it will recreate all the thumbs of you choose' - recreate_thumb: 'Frame color' + frame_color: 'Frame color' 'recreate': 'Apply' transparent: transparent checked: select all diff --git a/config/locales/zh_tw.yml b/config/locales/zh_tw.yml index c39f319..5e72d6b 100644 --- a/config/locales/zh_tw.yml +++ b/config/locales/zh_tw.yml @@ -2,6 +2,11 @@ zh_tw: gallery: setting: 相簿設定 + advanced_setting: 進階設定 + thumb_process_option_trans: 縮圖處理選項 + thumb_process_option: + - 縮放並填充 + - 僅縮放 inner_page_layout: 內頁頁面樣式 card_style: 卡片樣式 grid_style: 格子排版樣式 @@ -61,7 +66,7 @@ zh_tw: progressbar: 進度條 error: '重新產生縮圖失敗,請聯絡客服或稍後再試' 'sure?': '您真的确定要套用嗎? 會重新產生整個相簿的縮圖喔!' - recreate_thumb: 相框底色 + frame_color: 相框底色 transparent: 透明 checked: 全選 unchecked: 全部反選