Unable to upload and process image with CarrierWave and MiniMagick - ruby-on-rails

I am trying to implement image-upload with CarrierWave and MiniMagick. I was able to upload an image with carrierwave, but when I implemented MiniMagick to resize uploaded images, it returned this error:
Errno::ENOENT in ItemsController#create
No such file or directory - identify -ping /var/folders/6y/j8zfcgmd02x5s439c0np8fjh0000gn/T/mini_magick20121228-71203-bdoeul.jpg
image_uploader.rb
class ImageUploader < CarrierWave::Uploader::Base
include CarrierWave::MiniMagick
storage :file
def store_dir
"uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
end
version :thumb do
process :resize_to_fill => [100, 100]
end
end
I have imagemagick installed.

Not sure what went wrong, but after I uninstalled MacPort and all its ports, installed Homebrew and reinstalled ImageMagick, everything works as expected.

Related

Image uploading issue with Carrierwave and Minimagick (Ruby on rails)

I am using Carrierwave to upload images and that works fine but I am now trying to use Minimagick to process these uploaded images.
What is going on?
The images still upload as well as their thumb version, however both images are exactly the same size.
Here is the uploader code:
class FileUploader < CarrierWave::Uploader::Base
include CarrierWave::MiniMagick
# Choose what kind of storage to use for this uploader:
storage :file
# Override the directory where uploaded files will be stored.
def store_dir
"uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
end
# Create different versions of your uploaded files:
version :thumb do
process :resize_to_fit => [100, 100]
end
# Add a white list of extensions which are allowed to be uploaded.
def extension_white_list
%w(jpg jpeg gif png)
end
end
And here is how I am calling it:
<%= image_tag example.my_file.url(:thumb).to_s %>
I dont think it is anything to do with the way I am calling it because the two files created by all this are the same, so sound slike its to do with processing it on upload.
Here is the folder created for each object:
Image
--- Fixed ---
The issue was ImageMagick. It was not properly configured on my machine so that means no gem that deals with image processing (Paperclip, Minimagick or Dragonfly) could complete any image manipulation.

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"

Carrierwave undefined metho auto_orient

I've been trying to use RMagick auto_orient method to fix mobile uploads. Currently they are rotated 90 degrees. My uploader file currently looks like this.
class AvatarUploader < CarrierWave::Uploader::Base
include CarrierWave::RMagick
storage :fog
def root
Rails.root.join 'public/'
end
include CarrierWave::MimeTypes
process :set_content_type
def store_dir
"uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
end
process :resize_to_fill => [200, 200]
version :thumb do
process :resize_to_fill => [50, 50]
end
process :auto_orient
def extension_white_list
%w(jpg jpeg gif png)
end
end
This is giving me an error
undefined local variable or method auto_orient for AvatarUploader:Class (NameError)
I've tried several solutions,
exif image rotation issue using carrierwave and rmagick to upload to s3, https://github.com/minimagick/minimagick/issues/68
but no dice.
Anyone got a clue what I'm doing wrong?
Try adding the following:
def auto_orient
manipulate! do |img|
img.auto_orient!
end
end
As it stands now, the auto_orient process you're referencing doesn't exist in the context, hence the error.
Edit: according to the imagemagick github link you posted, auto_orient! might be broken. You could then use auto_orient instead in a similar way (it just creates a new image instead of modifying the one passed to the method). Refer to the links you posted for possible solutions using the auto_orient method.

cant see the aws-s3 url saved in rails database

I have successfully implemented image uploading using carrierwave, fog and Amazon S3. In my imageuploader am using only fog as storage. But when i check my database i can see that just the file name is written instead of the amazon url. In my views its fetching correctly from aws without any issues.
Is it supposed to be like this?
If so how the application figure out the exact url to s3?
imageuploader.rb`
# encoding: utf-8
class ImageUploader < CarrierWave::Uploader::Base
# Include RMagick or MiniMagick support:
# include CarrierWave::RMagick
# include CarrierWave::MiniMagick
include CarrierWave::MiniMagick
#Include the sprockets-rails helper for Rails 4+ compatibility:
include Sprockets::Rails::Helper
storage :fog
version :index_size do
process :resize_to_fill => [258, 173]
end
version :thumb_size do
process :resize_to_fill => [100, 100]
end
def extension_white_list
%w(jpg jpeg gif png)
end
end
Your config has the bucket name and the database has the filename. These are the only two pieces of information that are actually required to construct a filename (and it can be done without other API calls). The urls are actually pretty regular, so it is fairly straightforward for the server to do this. Hope that helps!

Rails file upload gem like Paperclip, without the ImageMagick dependency?

Is there a Paperclip gem alternative, which does not require ImageMagick, for Rails 3.2.x projects?
CarrierWave have easy uploader interface.
There are RMagick and MiniMagic implemetations of thumbnail generators.
MiniMagic allows you to have the power of ImageMagick without having to worry about installing all the RMagick libraries:
class AvatarUploader < CarrierWave::Uploader::Base
include CarrierWave::MiniMagick
process :resize_to_fill => [200, 200]
end

Resources