Ruby on rails 复制载波电波图像会使图像变暗吗?
我有一个Ruby on rails 复制载波电波图像会使图像变暗吗?,ruby-on-rails,ruby,duplicates,activeadmin,carrierwave,Ruby On Rails,Ruby,Duplicates,Activeadmin,Carrierwave,我有一个事件模型,它有许多照片。我有一个图片上传安装到照片属性,并定期上传,一切正常 但是,当我尝试复制一个事件,为新事件重新创建一个新的照片对象时,新图像比原始图像暗,如果我复制复制的事件,它会变得更暗 我一直在玩弄它,但没有解决办法 我的上传程序代码: class ImageUploader < CarrierWave::Uploader::Base include CarrierWave::RMagick include CarrierWave::Processing::R
事件
模型,它有许多照片
。我有一个图片上传安装到照片属性,并定期上传,一切正常
但是,当我尝试复制一个事件,为新事件重新创建一个新的照片对象时,新图像比原始图像暗,如果我复制复制的事件,它会变得更暗
我一直在玩弄它,但没有解决办法
我的上传程序代码:
class ImageUploader < CarrierWave::Uploader::Base
include CarrierWave::RMagick
include CarrierWave::Processing::RMagick
def store_dir
"uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
end
def cache_dir
"#{Rails.root}/tmp/carrierwave"
end
process :colorspace => :rgb
# Remove EXIF data
process :strip
# Create different versions of your uploaded files:
version :thumb do
process :resize_to_limit => [640, 640]
end
version :preview_thumb do
process :resize_to_limit => [600, 600]
end
version :wine_thumb do
process :resize_to_limit => [160, 440]
end
version :logo_thumb do
process :resize_to_limit => [90, 90]
end
end
class ImageUploader:rgb
#删除EXIF数据
工艺:带钢
#创建上载文件的不同版本:
版本:thumb do
处理:将_调整为_限制=>[640640,640]
结束
版本:预览
处理:将_调整为_限制=>[600600]
结束
版本:葡萄酒
处理:将_调整为_限制=>[160440]
结束
版本:logo_thumb do
处理:将_调整为_限制=>[90,90]
结束
结束
和我的重复代码(在Active Admin中):
member\u操作:创建重复事件,方法::post do
old_event=event.find(参数[:id])
照片url=旧的事件.照片.地图(&:图像url)
属性=旧事件。属性。除了(“照片”、“id”)
新照片=[]
照片|
新照片({
远程\u图像\u url:照片
})
如果是新照片,请保存
新照片好的,经过大量的尝试和搜索,我成功地解决了这个问题
首先,您需要下载.icc颜色配置文件,可以找到。上面写的是windows,但它们似乎在我的Mac上对我有效
将.icc
文件放入/lib/color\u profiles
目录后,将以下代码添加到上载程序:
class ImageUploader < CarrierWave::Uploader::Base
include CarrierWave::RMagick
process :convert_image_from_cmyk_to_rgb
#versions, and any other uploader code go here
def convert_image_from_cmyk_to_rgb
manipulate! do |image|
if image.colorspace == Magick::CMYKColorspace
image.strip!
image.add_profile("#{Rails.root}/lib/USWebCoatedSWOP.icc")
image.colorspace == Magick::SRGBColorspace
image.add_profile("#{Rails.root}/lib/sRGB.icc")
end
image
end
end
end
class ImageUploader
这将CMYK图像转换为RGB,并保持轮廓保持良好,同时保持RGB图像不变,不会破坏它们
我希望这对将来的人有所帮助,并为他们节省我花在解决这个问题上的时间
class ImageUploader < CarrierWave::Uploader::Base
include CarrierWave::RMagick
process :convert_image_from_cmyk_to_rgb
#versions, and any other uploader code go here
def convert_image_from_cmyk_to_rgb
manipulate! do |image|
if image.colorspace == Magick::CMYKColorspace
image.strip!
image.add_profile("#{Rails.root}/lib/USWebCoatedSWOP.icc")
image.colorspace == Magick::SRGBColorspace
image.add_profile("#{Rails.root}/lib/sRGB.icc")
end
image
end
end
end