2017-02-05 5 views
0

저는 Paperclip을 사용하여 이미지를 변환하고 있습니다. 색 공간이 srgb로 설정되지 않은 경우 생성 된 이미지의 품질이 크게 저하되었습니다.유효화 Image Colorspace with Paperclip

업로드 된 이미지의 색상 공간을 확인하는 방법이 있습니까? 필자가 도움이 될 수도 절반 대답을 얻었다

답변

1

...

설치해야합니다

https://github.com/rmagick/rmagick이 모델에 추가

attr_accessor :image_colorspace 
validates_exclusion_of :image_colorspace, in: [Magick::CMYKColorspace], message: 'is not RGB' 
before_logo_post_process :read_image_colorspace 
def read_image_colorspace 
    self.image_colorspace = Magick::Image.from_blob(image.queued_for_write[:original].read).first.colorspace 
    true 
end 

(첨부 파일 이름 image를 교체합니다.)

... rmagick을 사용하지 않고 nix 시스템을 사용하려면 다음을 수행 할 수 있습니다.

attr_accessor :image_colorspace 
validates_exclusion_of :image_colorspace, in: ['CMYK'], message: 'is not RGB' 
before_logo_post_process :read_image_colorspace 
def read_image_colorspace 
    self.logo_colorspace = `identify -verbose %m "#{image.queued_for_write[:original].path}" | grep 'Colorspace'`.to_s.upcase.strip.split(' ').last 
    true 
end