Tag: imagemagick

带有ImageMagick和Rails的像素RGB

我目前正在使用PaperClip和ImageMagick上传图像。 我想得到图像的平均颜色,所以我这样做(使用before_create挂钩): def get_average_color img = Magick::Image.read(self.url).first pix = img.scale(1, 1) averageColor = pix.pixel_color(0,0) end 这有效,但当我尝试打印像素颜色时,我得到它们像这样: red=36722, green=44474, blue=40920, opacity=0 如何将这些RGB值转换为常规(0-255)RGB值。 我只是修改它们吗? 提前致谢。

如何在Windows上安装rmagick gem?

如何为Windows XP安装rmagick gem? 我已经使用头文件安装了ImageMagick,并安装了DevKit附带的RailsInstaller.org。 我不知道在哪里修复这些错误。 C:\RailsInstaller\ImageMagick-6.8.2-Q16>ruby -v ruby 1.9.3p125 (2012-02-16) [i386-mingw32] C:\RailsInstaller\ImageMagick-6.8.2-Q16>gem -v 1.8.16 C:\RailsInstaller\ImageMagick-6.8.2-Q16>path=%PATH%;C:\RailsInstaller\ImageMagick-6.8.2-Q16 C:\RailsInstaller\ImageMagick-6.8.2-Q16>identify Version: ImageMagick 6.8.2-0 2013-01-24 Q16 http://www.imagemagick.org Copyright: Copyright (C) 1999-2013 ImageMagick Studio LLC C:\RailsInstaller\ImageMagick-6.8.2-Q16>gem install rmagick Temporarily enhancing PATH to include DevKit… Building native extensions. This could take a while… ERROR: Error installing rmagick: ERROR: Failed to build gem […]

了解ImageMagick的转换并转换为Ruby RMagick

我无法将以下PHP / ImageMagick代码转换为Ruby RMagick(以使其对未来用户更易于管理并了解它的真正用途): $output = array(); $returnValue = 0; $pngFiles = $myDir->find(“/.png$/i”); foreach($pngFiles as $pngFile) { $cmd = ‘convert ‘.$pngFile->path.’ -resize 1×1 -alpha on -channel o -format “%[fx:ua]” info:’ exec($cmd, $output, $returnValue); if($output[0] != 1) { logMessage(“PNG file contains some alpha transparency and will not be modified”); } } 到现在为止,我认为我或多或少地理解了convert-command正在做什么,但将其翻译成RMagick让我重新思考。 例如:为什么$output[0] != 1 有时在$myDir […]

ImageMagick安装Windows

我正在尝试在Windows上安装ImageMagick。 我做的是安装Windows RailsInstaller创建我的版本,现在我需要使用ImageMagick但由于某种原因它不起作用。 我拿了二进制源代码并从这个页面安装并运行它,但似乎没有做到这一点http://www.imagemagick.org/script/binary-releases.php#windows 我也尝试以下http://www.youtube.com/watch?v=gEWAVlNCKhg但它不起作用 对于第一个例子在cmd中我所要做的就是以下命令让我理解为使它在这里工作得到的东西 C:\Sites\case>convert wizard: wizard.jpg Invalid Parameter – wizard.jpg C:\Sites\case>convert wizard.jpg Invalid drive specification. C:\Sites\case>convert logo: logo.gif Invalid Parameter – logo.gif C:\Sites\case>$ convert logo: logo.gif ‘$’ is not recognized as an internal or external command, operable program or batch file. C:\Sites\case> 然后我看到了这个。 从https://github.com/rmagick/rmagick说它包括rmagick然后我运行bundle并得到这个 Installing rmagick (2.13.2) Gem::Installer::ExtensionBuildError: ERROR: Failed to build […]

找不到回形针文件错误

我刚刚从回形针导轨插件切换到回形针gem。 该项目是rails 2.3应用程序,我正在使用paperclip 2.7.2 gem。 我收到以下奇怪的错误: identify: unable to open image `file’: No such file or directory @ error/blob.c/OpenBlob/2617. identify: no decode delegate for this image format `file’ @ error/constitute.c/ReadImage/544. 看起来像paperclip正在寻找一个名为’file’的文件,但我不知道为什么。 我没有改变以前的任何代码。 它曾经工作过,我所做的只是升级到更新的版本并在插件上使用gem。 有任何想法吗? 更新 这是一个纸夹中的错误,它不能正确解析命令的内容。 我深入研究回形针来源,找到: def run(cmd, arguments = “”, local_options = {}) if options[:image_magick_path] Paperclip.log(“[DEPRECATION] :image_magick_path is deprecated and will be removed. […]

使用Ruby和imagemagick获取或计算图像的熵

如何在Ruby中找到带有imagemagick的“entropy”,最好是mini_magic? 我需要这个作为一个更大的项目的一部分, 在图像中找到“有趣”,以便裁剪它 。 我在Python / Django中找到了一个很好的例子 ,它提供了以下伪代码: image = Image.open(‘example.png’) histogram = image.histogram() # Fetch a list of pixel counts, one for each pixel value in the source image #Normalize, or average the result. for each histogram as pixel histogram_recalc << pixel / histogram.size endfor #Place the pixels on a logarithmic scale, to enhance […]

Heroku:使用回形针运行imagemagick

我在我的mac os x计算机上安装了image magick,现在我想将它部署到heroku。 我在heroku上安装了paperclip插件,但上传图片时出现此错误: Paperclip::CommandNotFoundError 之前我在计算机上没有imagemagick instaledl时出现此错误,但现在我想部署它, 如何让图像magick在heroku上工作?

为什么Ruby open-uri打开在我的unit testing中返回一个StringIO,但在我的控制器中是一个FileIO?

我inheritance了一个Rails 2.2.2应用程序,用于在Amazon S3上存储用户上传的图像。 基于attachment_fu的Photo模型提供了一种rotate方法,该方法使用open-uri从S3和MiniMagick中检索图像以执行旋转。 rotate方法包含此行以检索用于MiniMagick的图像: temp_image = MiniMagick::Image.from_file(open(self.public_filename).path) self.public_filename返回类似的内容 http://s3.amazonaws.com/bucketname/photos/98/photo.jpg 检索图像并旋转它在生产和开发中运行的应用程序中工作得很好。 但是,unit testing失败了 TypeError: can’t convert nil into String /Users/santry/Development/totspot/vendor/gems/mini_magick-1.2.3/lib/mini_magick.rb:34:in `initialize’ /Users/santry/Development/totspot/vendor/gems/mini_magick-1.2.3/lib/mini_magick.rb:34:in `open’ /Users/santry/Development/totspot/vendor/gems/mini_magick-1.2.3/lib/mini_magick.rb:34:in `from_file’ 原因是当在unit testing的上下文中调用模型方法时, open(self.public_filename)返回包含图像数据的StringIO对象。 此对象上的path方法返回nil并且MiniMagick::Image.from_file爆炸。 当从PhotosController调用这个相同的模型方法时, open(self.public_filename)返回绑定到名为/tmp/open-uri7378-0的文件的FileIO实例,该文件包含图像数据。 考虑原因必须是测试和开发之间的一些环境差异,我在开发环境下启动了控制台。 但就像在unit testing中一样, open(‘http://…’)返回了一个StringIO , 而不是 FileIO 。 我已经通过open-uri和所有相关的应用程序特定代码进行了跟踪,并且没有找到差异的理由。

无法安装rmagick,找不到pkg-config:命令

我正在尝试在我的Mac OS X v10.9 (Mavericks)机器上安装rmagick。 然而。 我收到这个错误 /usr/local/bin/Magick-config: line 41: pkg-config: command not found /usr/local/bin/Magick-config: line 47: pkg-config: command not found /usr/local/bin/Magick-config: line 50: pkg-config: command not found /usr/local/bin/Magick-config: line 53: pkg-config: command not found checking for stdint.h… yes checking for sys/types.h… yes checking for wand/MagickWand.h… yes /usr/local/bin/Magick-config: line 53: pkg-config: command not found Can’t […]

使用RMagick将CMYK图像正确转换为RGB

我一直在使用下面的颜色转换 if @image.colorspace == Magick::CMYKColorspace # @image.colorspace #=> CMYKColorspace=12 @image.colorspace = Magick::RGBColorspace @image = @image.negate end 它大约有效,但颜色亮度不对。 我需要否定图像的事实留下了非常难闻的气味。 该文档提到了使用color_profiles,但除此之外我找不到多少。 我现在正在努力 @image = @image.quantize(16777216, Magick::RGBColorspace) 颜色更好,但仍然关闭。