开发者

Rails - WIndows 7 carrierwave, minimagick resize not working

开发者 https://www.devze.com 2023-04-13 01:14 出处:网络
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 uplo

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' \244\243\254O\244\272\263\241\251Υ~\263\241\251R\245O\241B............", :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


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)


Step 1: Check if mini_magick is working properly

  • You must have ImageMagick or GraphicsMagick installed.

Step 2. Try following command on your irb

> irb
> require 'mini_magick'
> filename = '/Users/me/tmp/testfile.jpg'
> image = MiniMagick::Image.open(filename)
  • If you are getting errors while running this program like "no decode delegate for this image format" go to Step 3.

Step 3: Check Imagemagick supported formats

> identify -list format
  • The list must have jpg listed. If not go to Step 4.

Step 4. Download and install decode delegates for Imagemagick

Site: http://www.imagemagick.org/download/delegates/

> tar -zxvf jpegsrc.v8b.tar.gz
> cd jpegsrc.v8b
> sudo ./configure
> sudo make
> sudo make install
  • After that re-install the Imagemagick
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号