带有ImageMagick和Rails的像素RGB [英] Pixel RGB with ImageMagick and Rails

查看:114
本文介绍了带有ImageMagick和Rails的像素RGB的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在使用PaperClip和ImageMagick上传图片。我想得到图像的平均颜色,所以我这样做(使用before_create挂钩):

I'm currently uploading an image with PaperClip and ImageMagick. I would like to get the image's average color so I'm doing this (with a before_create hook):

def get_average_color           
    img =  Magick::Image.read(self.url).first
    pix = img.scale(1, 1)
    averageColor = pix.pixel_color(0,0)
end 

这样可行,但是当我尝试打印像素颜色时,我得到这样的颜色:

This works but when I try to print the pixel colors out I get them like this:

red=36722, green=44474, blue=40920, opacity=0 

如何将这些RGB值转换为常规(0-255)RGB值。我只是修改它们吗?在此先感谢。

How can I get these RGB values into regular (0-255) RGB values. Do I just mod them? Thanks in advance.

推荐答案

您的ImageMagick的编程深度为16位,而不是8位。请参阅这篇文章在RMagick Hints&提示论坛了解更多信息。

Your ImageMagick is compiled for a quantum depth of 16 bits, versus 8 bits. See this article in the RMagick Hints & Tips Forum for more information.

这篇关于带有ImageMagick和Rails的像素RGB的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆