Задать вопрос
@kramidev

Не работает resize Carrierwave and ImageMagick?

Привет всем. У кого проблема с ресайзом и юзаньем ImageMagick.
Перестала 2 дня уже ресайзится фото.
Файлы грузит в public/uploads/tmp

Указывает оба оригинал и thumb. Фото не ресайзится, thumb равен оригинальной фото. И не грузится по store_dir. В чем проблема?

new.html.erb
<%= form_for @image, html: { multipart: true } do |f| %>
	<%= f.file_field :image %>
	<%= f.submit %>
<% end %>


ImagesController

class ImagesController < ApplicationController

	def new
		@image = Image.new
	end

	def create
		# render text: params
		@image = Image.new(images_params)
		if @image.save
			redirect_to root_path
		else
			render 'new'
		end
	end

	private

	def images_params
		params.require(:image).permit(:image)		
	end
end


Image.rb
class Image < ActiveRecord::Base
	mount_uploader :image, ImageUploader
end


Миграция

class CreateImages < ActiveRecord::Migration
  def change
    create_table :images do |t|
	  t.string :image

      t.timestamps null: false
    end
  end
end


Image_Uploader

# encoding: utf-8

class ImageUploader < CarrierWave::Uploader::Base

  # Include RMagick or MiniMagick support:
  # include CarrierWave::RMagick
  include CarrierWave::MiniMagick

  # Choose what kind of storage to use for this uploader:
  storage :file
  # storage :fog

  # Override the directory where uploaded files will be stored.
  # This is a sensible default for uploaders that are meant to be mounted:
  def store_dir
    "uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
  end

  # Provide a default URL as a default if there hasn't been a file uploaded:
  # def default_url
  #   # For Rails 3.1+ asset pipeline compatibility:
  #   # ActionController::Base.helpers.asset_path("fallback/" + [version_name, "default.png"].compact.join('_'))
  #
  #   "/images/fallback/" + [version_name, "default.png"].compact.join('_')
  # end

  # Process files as they are uploaded:
  # process :scale => [200, 300]
  #
  # def scale(width, height)
  #   # do something
  # end

  # Create different versions of your uploaded files:
  version :thumb do
    process :resize_to_fit => [50, 50]
  end

  # Add a white list of extensions which are allowed to be uploaded.
  # For images you might use something like this:
  # def extension_white_list
  #   %w(jpg jpeg gif png)
  # end

  # Override the filename of the uploaded files:
  # Avoid using model.id or version_name here, see uploader/store.rb for details.
  # def filename
  #   "something.jpg" if original_filename
  # end

end


gemfile
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.2.1'
# Use postgresql as the database for Active Record
gem 'pg'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 5.0'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# Use CoffeeScript for .coffee assets and views
gem 'coffee-rails', '~> 4.1.0'
# See https://github.com/rails/execjs#readme for more supported runtimes
# gem 'therubyracer', platforms: :ruby

# Use jquery as the JavaScript library
gem 'jquery-rails'
gem 'carrierwave'
gem 'mini_magick'


Вот еще инфо.
Failed to manipulate with MiniMagick, maybe it is not an image? Original Error: `identify /tmp/mini_magick20150406-31926-mm4j4l.jpg` failed with error: identify: no decode delegate for this image format `JPEG' @ error/constitute.c/ReadImage/501.

Как решить?
  • Вопрос задан
  • 756 просмотров
Подписаться 1 Оценить Комментировать
Пригласить эксперта
Ответы на вопрос 1
viktorvsk
@viktorvsk
Может пакет неудачно обновился?
Такое смотрели blog.ericlamb.net/2008/11/fix-for-convert-no-decod... www.imagemagick.org/discourse-server/viewtopic.php... ?
Что если вручную делать преобразования с консоли ?
Ответ написан
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Похожие вопросы