0
RoR에서 Carrierwave/Minimagick 보석을 사용하여 간단한 이미지 업 로더를 구현하는 데 문제가 있습니다.업로드 후 이미지를 처리하지 않는 Carrierwave/Minimagick
업로드 할 때 파일을 회색 음영으로 변환하려고하는데 오류가 발생합니다. 여기 코드는 다음과 같습니다
image_uploader.rb :
class ImageUploader < CarrierWave::Uploader::Base
include CarrierWave::MiniMagick
# Include the Sprockets helpers for Rails 3.1+ asset pipeline compatibility:
include Sprockets::Helpers::RailsHelper
include Sprockets::Helpers::IsolatedHelper
storage :file
def store_dir
"uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
end
# Process files as they are uploaded:
process :convert_to_grayscale
def convert_to_grayscale
manipulate! do |img|
img.quantize(256, Magick::GRAYColorspace)
img = yield(img) if block_given?
img
end
end
내가 파일을 업로드하려고, 나는 다음과 같은 오류 얻을 :
uninitialized constant ImageUploader::Magick
app/uploaders/image_uploader.rb:36:in `block in convert_to_grayscale'
app/uploaders/image_uploader.rb:35:in `convert_to_grayscale'
나는 이것이 때문입니다 생각을 Magick :: GRAYColorspace 열거 형 상수. 이 아이디어가 왜 작동하지 않는지 아십니까?
carrierwave 문서에 대한 조작 말씀이다() :!
다음은 샘플 예입니다. 이 메서드는 이미지를로드 한 다음 각 프레임을 제공된 블록으로 전달합니다. 그런 다음 이미지를 디스크에 저장합니다. 고치아 이 메서드는 개체가 current_path에 응답한다고 가정합니다. 이 모듈이 혼합되는 모든 클래스에는 current_path 메소드가 있어야합니다. CarrierWave :: Uploader는 대부분의 경우이 점에 대해 걱정할 필요가 없습니다. 조작이 실패하면 을 수행 할 수 수익률 MiniMagick :: 이미지 조작은 CarrierWave :: ProcessingError 를 발생시킵니다. – diego