CarrierWave: `maybe it is not an image? Original Error: `mogrify -strip!` - carrierwave

Using Carrierwave 1.3.1 on Rails 5.1.6.2 app.
When uploading a large image, getting a...
Failed to manipulate with MiniMagick, maybe it is not an image? Original Error: `mogrify -strip! /var/folders/19/hzl_0_sx19xf5sz8q2zhxh7w563yd8/T/mini_magick20190507-46146-6n4v4m.jpg` failed with error: mogrify: unrecognized option `-strip!' # error/mogrify.c/MogrifyImageCommand/6253.
in carrierwave.rb
def strip
manipulate! do |img|
img.strip!
img = yield(img) if block_given?
img
end
end

Related

Rails | Carrierwave rotates image 90 degrees

I am uploading images to s3 using fog and carrierwave. I am using the below code for profile picture:
version :listpic do
process :resize_to_fill_modfied => [100, 100]
end
version :usershow do
process :resize_to_fill_modfied => [225, 225] #user profile pic kullanılıyor
end
def resize_to_fill_modfied(width, height, gravity=::Magick::CenterGravity)
manipulate! do |img|
img.crop_resized!(width, height, gravity) unless (img.columns <= width && img.rows <= height)
img = yield(img) if block_given?
img
end
end
The problem is, when I try to upload an image 193x193 it rotates to 90 degrees to left. Why is that?
EDIT
When I try to upload 250x250 it again rotates.
I see from the comments on the question that you've "tried all the solutions," but have you installed MiniMagick?
# Add this in your Gemfile after CarrierWave and Fog:
gem 'mini_magick'
# then run `bundle install`
Once you've done that, try again with this in the uploader:
def fix_exif_rotation
manipulate! do |img|
img.tap(&:auto_orient)
end
end

Altering CarrierWave error message when catching error from rmagick

I am using CarrierWave + rmagick gems to upload image to server. When I am uploading a normal file, everything goes fine. But when I upload malformed file, the form error doesn't display CarrierWave error, it displays the error which appears when running rmagick.
A simple example. I have User model, and an uploader inside it like that:
class User < ActiveRecord::Base
...
mount_uploader :avatar, PictureUploader
end
(the avatar is a stringfield)
Now, the uploader is defined here:
class BaseImageUploader < CarrierWave::Uploader::Base
include CarrierWave::RMagick
storage :fog
def extension_white_list
%w(jpg jpeg gif png)
end
end
class PictureUploader < BaseImageUploader
def default_url
'placeholder.png'
end
def store_dir
'images/pictures'
end
version :thumb do
process resize_to_fit: [50, 50]
end
version :medium do
process resize_to_fill: [400, 400]
end
version :small_square do
process resize_to_fill: [200, 200]
end
end
Then I create an empty file, for example, with touch ~/Desktop/file.jpg, and trying to upload it via the form, and here I am getting a validation error:
Avatar Failed to manipulate with rmagick, maybe it is not an image? Original Error: Empty input file `<foldername>/public/uploads/tmp/1470905765-10111-5893/thumb_file.jpg' # error/jpeg.c/JPEGErrorHandler/322
I tried using ming_magick instead of rmagick, but the result is the same (with slightly different error message)
Can I do something to alter this validation message to say something like Avatar Your image is invalid instead of the default?
Hm, actually that was pretty easy: I just needed to add a string to i18n, like that:
errors.messaging.rmagick_processing_error: "Error processing image"

Heroku ImageMagick gives error: ArgumentError (no images in this image list):

I am trying to crop an image using ImageMagick (rmagick gem) on a Heroku rails server. Here is my code:
class PhotoUploader < CarrierWave::Uploader::Base
include CarrierWave::RMagick
#include CarrierWave::MiniMagick
storage :file
def store_dir
"uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
end
def crop
if model.crop_x.present?
manipulate! do |img|
x = model.crop_x.to_i
y = model.crop_y.to_i
w = model.crop_w.to_i
h = model.crop_h.to_i
img.crop!(x, y, w, h)
puts "officially cropped!"
end
end
end
version :standard do
process :crop
resize_to_limit(2000, 2000)
end
end
Here is the error it keeps throwing at me:
2016-03-03T12:18:22.236892+00:00 app[web.1]: Completed 500 Internal
Server Error in 296ms 2016-03-03T12:18:22.243033+00:00 app[web.1]:
2016-03-03T12:18:22.243040+00:00 app[web.1]: ArgumentError (no images
in this image list): 2016-03-03T12:18:22.243041+00:00 app[web.1]:
app/uploaders/photo_uploader.rb:21:in `crop'
2016-03-03T12:18:22.243046+00:00 app[web.1]:
Any ideas?
You will need to include the ImageMagick buildpack. Heroku does not include the necessary files for rmagick without it. https://github.com/ello/heroku-buildpack-imagemagick
This will also require you to run multiple buildpacks. https://devcenter.heroku.com/articles/using-multiple-buildpacks-for-an-app

CarrierWave Backgrounder not uploading versions images to AWS S3

I was using carrierwave 0.10.0 gem with RMagic to upload images on AWS S3. Everything was working fine except it was taking too much time to upload on AWS S3. So thought using carrierwave backgrounder to upload images in background. I set up carrierwave backgrounder (0.4.2) but In this one My original file is always get upload to S3 but versions of that image is never gets uploaded on S3.
Here is my carrierwave_backgrounder.rb
CarrierWave::Backgrounder.configure do |c|
c.backend :sidekiq, queue: :carrierwave
end
I have defined my queue in sidekiq.rb
Sidekiq.configure_server do |config|
config.redis = { :url => "redis://#{ENV['REDIS_ENDPOINT']}:6379", :namespace=> "#{ENV['REDIS_NAMESPACE']}" }
config.options =
queues: %w{
critical
carrierwave
}
})
end
Here is my photo_uploader.rb
class PhotoUploader < CarrierWave::Uploader::Base
include ::CarrierWave::Backgrounder::Delay
include CarrierWave::RMagick
storage :fog
def store_dir
"uploads/images/"
end
def filename
"#{secure_token}.#{file.extension}" if original_filename.present?
end
def orient_image
manipulate! do |img|
img.auto_orient
img
end
end
# Create different versions of your uploaded files:
version :thumb_small do
process :resize_to_fill => [100,100]
process :strip
end
def strip
manipulate! do |img|
img.strip!
img = yield(img) if block_given?
img
end
end
def extension_white_list
%w(jpg jpeg gif png)
end
def get_version_dimensions
model.width, model.height = `identify -format "%wx%h " #{file.path}`.split(/x/)
end
protected
def secure_token
var = :"##{mounted_as}_secure_token"
model.instance_variable_get(var) || model.instance_variable_set(var, SecureRandom.hex(5))
end
end
Here is my profile.rb file
mount_uploader :image_url, PhotoUploader
process_in_background :image_url
I have started the sidekiq worker using this command
bundle exec sidekiq -d -L log/sidekiq.log -C config/sidekiq.yml -e development
When I upload image_url only the original image is uploaded. This is sidekiq log after uploading original file. But I don't see any version file uploaded. I checked the S3 bucket also(No version file only the original file)
2016-01-11T08:52:20.772Z 3983 TID-ownpyrrxk CarrierWave::Workers::ProcessAsset JID-91e3803d50defb2d1419cef1 INFO: start
2016-01-11T08:52:31.119Z 3983 TID-ownpyrrxk CarrierWave::Workers::ProcessAsset JID-91e3803d50defb2d1419cef1 INFO: done: 10.347 sec
Is There something I am missing. Please Help
Thanks in Advance
After investigating with few documentations, here is my suggestion:
From careerwave_backgrounder readme: https://github.com/lardawge/carrierwave_backgrounder#background-options
Its clearly shows,
# This stores the original file with no processing/versioning.
# It will upload the original file to s3.
From this #113 , the author said
I found a bug related to Rmagick but no issue with versions
You can try with MiniMagick/ImageMagick instead of RMagick.
Documentation to look for the similar issue:
https://github.com/lardawge/carrierwave_backgrounder/issues/113
https://github.com/lardawge/carrierwave_backgrounder/issues/130
Rails CarrierWave versions are not created for some reason
Thanks!

Carrierwave/Minimagick not processing images after upload

I am having trouble implementing a simple image uploader with Carrierwave/Minimagick gems in RoR.
I'm trying to convert the file to grayscale upon upload, but I am getting an error. Here is the code:
image_uploader.rb:
class ImageUploader < CarrierWave::Uploader::Base
include CarrierWave::MiniMagick
# Include the Sprockets helpers for Rails 3.1+ asset pipeline compatibility:
include Sprockets::Helpers::RailsHelper
include Sprockets::Helpers::IsolatedHelper
storage :file
def store_dir
"uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
end
# Process files as they are uploaded:
process :convert_to_grayscale
def convert_to_grayscale
manipulate! do |img|
img.quantize(256, Magick::GRAYColorspace)
img = yield(img) if block_given?
img
end
end
When I try to upload a file, I get the following error:
uninitialized constant ImageUploader::Magick
app/uploaders/image_uploader.rb:36:in `block in convert_to_grayscale'
app/uploaders/image_uploader.rb:35:in `convert_to_grayscale'
I believe this is due to the Magick::GRAYColorspace enum constant. Any ideas why this isnt working?
Is the manipulate function that loads images to memory? Does It return a image list?
I think that the images aren't loaded correctly. The problem isn't the Magick enum.
Here is a sample example:
require 'RMagick'
clown = Magick::ImageList.new("clown.jpg")
clown = clown.quantize(256, Magick::GRAYColorspace)
clown.write('monochrome.jpg')

Resources