Tag: imagemagick

‘identify’命令无法识别Paperclip :: NotIdentifiedByImageMagickError图像

当我删除与其关联的图像并且我选择另一个时,我在编辑模型时遇到此错误: Paperclip::NotIdentifiedByImageMagickError in Admin/packsController#update Chrysanthemumprueba4.jpg is not recognized by the ‘identify’ command. C:/Users/…/vendor/plugins/thoughtbot-paperclip-fc792c8/lib/paperclip/geometry.rb:24:in `from_file’ 但是当我创建一个新包并为其选择图像时,它可以正常工作。 我有两个表:pack和pack_images,pack_images有相关包的照片,这里是关系: class Pack :destroy end class PackImage “/:attachment/:class/:id/:style_:basename.:extension”, :styles => {:principal => “240×240>”, :original => “400×400>”, …} end 这是控制器的操作,它会引发错误: def update @pack = Pack.find(params[:id]) @pack.pack_products unless params[:pack][:pack_images_attributes].nil? params[:pack][:pack_images_attributes].count.times do |i| unless params[:pack][:pack_images_attributes][:”#{i.to_s}”][:photo].blank? file = params[:pack][:pack_images_attributes][:”#{i.to_s}”][:photo] dimensions = Paperclip::Geometry.from_file(file) @pack.pack_images[i].width = […]

RMagick返回零读取JPEG

当我尝试使用RMagick在Rails中打开JPEG格式文件时,它总是返回任何jpg文件的nil。 其他文件格式打开很好。 $ script/console Loading development environment (Rails 2.3.4) >> require ‘RMagick’ >> img = Image.read(“1.gif”).first => 1.gif GIF 230×100 230×100+0+0 PseudoClass 256c 8-bit 2kb >> img = Image.read(“1.png”).first => 1.png PNG 1280×800 1280×800+0+0 DirectClass 8-bit 156kb >> img = Image.read(“1.jpg”).first => nil 为什么会这样?

如何使用Carrierwave和MiniMagick(Ruby on Rails)将PDF转换为图像数组

我正在将上传的PDF转换为图像,每页只有一个图像。 我已经想出如何使用MiniMagick::Tool::Convert生成图像,但我不知道如何为Uploader编写version块,以便我可以访问图像URL数组。 到目前为止,这是我的上传者: class DocumentUploader < CarrierWave::Uploader::Base include CarrierWave::MiniMagick storage :file # storage :fog def store_dir "uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}" end version :jpg do process :convert_to_images process :set_content_type_jpg def convert_to_images(*args) image = MiniMagick::Image.open(current_path) image.pages.each_with_index do |page, index| MiniMagick::Tool::Convert.new do |convert| convert.background 'white' convert.flatten convert.density 300 convert.quality 95 convert << page.path convert << "#{CarrierWave.root}/#{store_dir}/image-#{index}.jpg" end end end end def […]

如何在Rails应用程序中使用mini_magick获取EXIF关键字?

我正在尝试为具有EXIF“关键字”属性值的图像提取EXIF信息。 我已经使用mini_magick成功读取了EXIF信息,只需打开图像并使用: image[“EXIF:Model”] 出于某种原因,以下所有内容都不会返回我知道的图像的关键字: image[“EXIF:Keywords”] image[“EXIF:XPKeywords”] image[“EXIF:Subject”] 我已使用此实用程序确认相关图像确实包含此信息: http : //regex.info/exif.cgi mini_magick只能访问某些EXIF值吗? 看起来很奇怪,我可以访问某些EXIF信息但不能访问其他信息。

水印图像用回形针,导轨4

我一直在尝试为我的图像添加水印,按照水印中使用回形针列出的答案: Watermark.rb: module Paperclip class Watermark < Processor # Handles watermarking of images that are uploaded. attr_accessor :current_geometry, :target_geometry, :format, :whiny, :convert_options, :watermark_path, :watermark_offset, :overlay, :position def initialize file, options = {}, attachment = nil super geometry = options[:geometry] @file = file @crop = geometry[-1,1] == '#' @target_geometry = Geometry.parse geometry @current_geometry = Geometry.from_file @file […]

使用ImageMagick进行Brew链接

安装: ostaptan:~ostap $ brew install imagemagick –disable-openmp –from-source ==> Downloading http://downloads.sf.net/project/machomebrew/mirror/ImageMagick-6.7.7-6.tar.bz2 Already downloaded: /Library/Caches/Homebrew/imagemagick-6.7.7-6.tar.bz2 ==> Patching patching file configure Hunk #1 succeeded at 32371 (offset 447 lines). ==> ./configure –disable-osx-universal-binary –without-perl –prefix=/usr/local/Cellar/imagemagick/6.7.7-6 –enable-shared –disable-static ==> make install Error: The linking step did not complete successfully The formula built, but is not symlinked into /usr/local You […]

ImageMagick多行文本和背景图像

我正在学习使用ImageMagick,但是当我尝试生成如下例子的图像时遇到了麻烦: 为此,我使用以下代码: convert original.jpg -size 460x caption:’This is a multiline caption, This is a multiline caption, This is a multiline caption.’ result.jpg 此命令生成两个单独的图像,一个只有标题。 你能帮助我吗? PS:我正在使用带有ImageMagick的RubyOnRails,但您可以使用MiniMagick或Rmagick建议示例。 谢谢。

使用透明背景将PDF转换为PNG

我们有一个Ruby on Rails应用程序,需要将PDF转换为具有透明背景的PNG。 我们正在使用rmagick 2.13.1。 在我们的开发机器上,以下代码正是我们想要的。 pages = Magick::Image.from_blob(book.to_pdf.render){ self.density = 300 } page = pages[0] image_file = Tempfile.new([‘preview_image’, ‘.png’]) image_file.binmode image_file.write( page.to_blob { |opt| opt.format = “PNG” } ) 我们保存image_file,所有都是桃子。 但是,当我们部署到Heroku上的评论服务器时,生成的图像具有白色背景。 事实certificate,Heroku的雪松堆正在使用imagemagick ImageMagick 6.5.7-8 2010-12-02,我们在开发机器上使用ImageMagick 6.7.5-7 2012-05-08。 我已经在网上搜索了可能适用于旧版本的旧post,试图找出如何生成透明的PNG。 它肯定得到了支持,但到目前为止,我还没有找到正确的设置组合。 为了validation它不是PDF生成的问题,我下载了一个在Heroku上生成的PDF,并使用上面的代码(略微修改为读取文件而不是生成它)成功转换为透明PNG。 我在各种组合中尝试过的一些事情是: page.matte = true page.format = “PNG32” page.background_color = “none” page.transparent_color = “white” page.transparent(“white”) […]

作物与蜻蜓铁路的圆形图像

我正在使用dragonfly ~> 0.9.15 给定一个图像,我很困惑如何使用蜻蜓中的转换方法从透明背景的图像中裁剪圆形部分。 我可以使用直接图像magick命令从命令行运行它,但我找到的示例命令使用实际文件,我不知道如何获取文件,而dragonfly动态处理它。 这是我从imagemagick的堆栈溢出问题中获取的实际命令。 https://stackoverflow.com/a/999563/1664852 convert -size 200×200 xc:none -fill walter.jpg -draw “circle 100,100 100,1” circle_thumb.png 当我试图用dragonfly实现同样的function时,这就是配置: require ‘dragonfly/rails/images’ Dragonfly[:images].configure do |c| c.job :crop_circle do process :resize, “320×440” encode :png process :convert, ‘-virtual-pixel HorizontalTile -background transparent -draw “circle 400,400 400,1” -compose Copy_Opacity -composite’ end end 当它在服务器日志中运行时,我得到错误no such image 。 如何使用imagemagick命令为此配置convertfunction?

sh:识别:命令未找到imagemagick rails 3

我正在使用带有rails 3的ImageMagick-6.7.4并且还将paperclip gem安装到我的应用程序中。 我按照本指南安装了imagemagick ,它可以在我的终端上运行,但不适用于我的rails应用程序。 我在development.rb中包含了identify命令的路径 Paperclip.options[:command_path]=’/path-where-my-identify-got-installed/’ 但它仍然给我一个错误 Command :: identify -format %wx%h’/var/folders/Cd/CdjXsnlyEPyFqs4pwH83T++++TI/-Tmp-/stream20120104-2402-5iizym-0.png[0]'[paperclip] An error was received while processing: #Command :: identify -format %wx%h ‘/var/folders/Cd/CdjXsnlyEPyFqs4pwH83T++++TI/-Tmp-/stream20120104-2402-5iizym-0.png[0]'[paperclip] An error was received while processing: #SQL (0.1ms) BEGIN