0

我已经搜索过,但找不到任何有关使用Shrine上传 pdf 文件的信息。我有它的工作,但 pdf 是模糊和像素化的,即使在引用(:original)版本时也是如此。

初始化程序/shrine.rb

require 'shrine'
require 'shrine/storage/file_system'

Shrine.storages = {
    cache: Shrine::Storage::FileSystem.new('public', prefix: 'uploads/cache'),
    store: Shrine::Storage::FileSystem.new('public', prefix: 'uploads/store')
}

Shrine.plugin :activerecord
Shrine.plugin :backgrounding
Shrine.plugin :remove_attachment
Shrine.plugin :logging
Shrine.plugin :delete_raw
Shrine.plugin :upload_endpoint
Shrine.plugin :cached_attachment_data
Shrine.plugin :restore_cached_data
Shrine.plugin :determine_mime_type

image_uploader.rb

require 'image_processing/mini_magick'
class ImageUploader < Shrine
  ALLOWED_TYPES = %w[image/jpeg image/jpg image/png image/gif application/pdf]
  MAX_SIZE = 50
  include ImageProcessing::MiniMagick

  plugin :remove_attachment
  plugin :pretty_location
  plugin :processing
  plugin :versions
  plugin :validation_helpers
  plugin :store_dimensions
  plugin(:default_url) { |_| '/img/preview-not-available.jpg' }

  Attacher.validate do
    validate_max_size MAX_SIZE.megabytes, message: "is too large (max is #{MAX_SIZE} MB)"
    validate_mime_type_inclusion ALLOWED_TYPES
  end

  process(:store) do |io|
    original = io.download

    size_1500 = resize_to_limit!(original, 1500, 600)
    size_500 = resize_to_limit(size_1500, 500, 500)
    size_300 = resize_to_limit(size_500, 300, 300)

    { original: size_1500, medium: size_500, thumb: size_300 }
  end
end

产品/show.html.erb

...
<% if @product.spec_sheet.present? %>
  <div class="col-md-12">
    <%#= image_tag(@product.spec_sheet_cover_url(:original), class: 'border') %>
    <%= link_to @product.spec_sheet_url(:original), :class => 'btn', style: 'width: auto' do %>
          <span><%= image_tag 'pdf-icon.png', style: 'width: 10%;
              position: relative;
              right: 3px;
              bottom: 1px;' %> Collection Brochure</span>
    <% end %>
  </div>
<% end %>
... 
4

1 回答 1

0

我只是想通了我自己的问题......一直在我面前。通过引用:original,我选择了调整大小的版本。但是通过重构这条线,它使:original尺寸全分辨率。{ original: io, large: size_1500, medium: size_500, thumb: size_300 }

于 2018-08-04T07:47:37.743 回答