在图像magick中获取转换后的图像的问题

时间:2015-01-22 08:08:35

标签: ruby-on-rails-3.2 imagemagick imagemagick-convert

我想将我的所有图像转换为jpg格式,并保存在我上传图像时存储其他图像的同一文件夹中。所以添加了以下代码。

folder_path = "/#{@project.project_code}/prj#{self.attachment_folder}"
self.attachment_folder = folder_path
newfile = attachment_file_name[/[^.]+/]+ ".jpg"

然后使用system('convert #{folder_path}/#{self.attachment_file_name} #{folder_path}/#{newfile}')想要转换并将其保存在同一文件夹中......但是我的日志中没有收到任何错误,也没有在我的相应文件夹中看到转换后的文件。但我在日志中得到以下内容

By default, the image format of `file' is determined by its magic
number.  To specify a particular image format, precede the filename
with an image format name and a colon (i.e. ps:image) or specify the
image type as the filename suffix (i.e. image.ps).  Specify 'file' as
'-' for standard input or output.

我如何才能在同一个文件夹中看到我的转换文件?

我的代码如下:

if attachable_type.downcase == "project"
  @project = Project.select("projects.project_code").not_deleted.find_by_id(self.attachable_id) if !self.attachable_id.blank?
  if !@project.blank?
   user_nick_name = self.current_user_nick_name.downcase if !self.current_user_nick_name.blank?
   self.attachment_file_name.gsub!(/\.|_#{@user_id}\./,"_#{@user_id}.")
   file_name = (@project.project_code+"_"+user_nick_name+"_"+self.attachment_file_name).downcase if !user_nick_name.blank?
   #self.attachment_folder = "#{@project.project_code}/references/"
    folder_path = "/#{@project.project_code}/prj#{self.attachment_folder}"
    self.attachment_folder = folder_path
    newfile = attachment_file_name[/[^.]+/]+ ".jpg"
    puts "#{folder_path}/#{self.attachment_file_name}"
    puts "#{folder_path}/#{newfile}"
    puts "#{newfile}"
    # thumb = Magick::Image.read("#{folder_path}#{self.attachment_file_name}").first
    system('convert #{folder_path}/#{self.attachment_file_name} #{folder_path}/#{newfile}')
  end
end

输出为:

/bts/prj/references/animatic/RefineryCMS_284.png
/bts/prj/references/animatic/RefineryCMS_284.jpg
RefineryCMS_284.jpg

0 个答案:

没有答案