Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
306 views
in Technique[技术] by (71.8m points)

Rails - WIndows 7 carrierwave, minimagick resize not working

I tried to set up for uploading photos with my rails app. However, the carrierwave uploader does not resize the photos being uploaded. When I do not call the resize_to_fill function, the photos are uploaded perfectly. Any advice?

When a photo is submitted with resize_to_fill, the error 'failed to be processed' is returned. How can i fix it?

I guess I need to 'require' 'carrierwave/processing/mini_magick' for calling resize_to_fill, but i don't know where to put this file.

gemfile
"carrierwave", "0.4.10"
"mini_magick", "3.2.1"
"rails", "2.3.14"

Platform
win7 64bit
ruby 1.8.7 imagemagick (path = C:ImageMagick-6.7.2-Q16)

batterhead


thanks for your reply. Below is my coding, please advise.
i'm just thinking does the problem come from my combination of win7 + imagemagick + mini_magick + carrierwave? such a problem should have been reproduced easily by many people, i guess. are those versions incompatible with each other?

i just tested my application and tried to upload a photo again. a processing_error returned:
Failed to manipulate with MiniMagick, maybe it is not an image? Original Error: Command ("identify -ping C:/Users/User/mini_magick20111018-4296-f18lsi-0.jpg") failed: {:output=>"'identify' 244243254O244272263241251Υ~263241251R245O241B............", :status_code=>1}
of course the jpg was not created in C:/Users/User folder. please help.

{avatar_uploader.rb}  
class AvatarUploader < CarrierWave::Uploader::Base  
  include CarrierWave::MiniMagick  
  storage :file  
  def store_dir  
    "uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"  
  end

  process :resize_to_fill => [320, 240]

  def extension_white_list  
    %w(jpg jpeg gif png)  
  end  
end

{event_photo.rb}  
class EventPhoto < ActiveRecord::Base  
  attr_accessible :event_id, :avatar, :created_by, :updated_by  

  belongs_to:event
  mount_uploader :avatar, AvatarUploader  
end

{preinitializer.rb}  
begin  
  require 'rubygems'  
  require 'bundler'  
end
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I've run into a similar issue, though not on Windows, though this information may help.

From the Github page on MiniMagick (https://github.com/probablycorey/mini_magick/), it seems that MiniMagik relies on the "mogrify" command.

The first step in my debugging the issue was to ensure that the correct libraries were built on my dev, staging and production systems and that the "mogrify" command was available.

To get there, on my OS/X system, I had to uninstall and reinstall ImageMagik, which I did with macports.

I verified the installation with "identify filename" and then did the following in Rails console:

filename = '/Users/me/tmp/testfile.jpg'
image = MiniMagick::Image.open(filename)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...