Rails : RMagick : Failed to manipulate; improper image header

In your app if you have used RMagick library to manipulate image files; viz. crop, resize, draw, etc. you may stumble upon such issues if have missed some scenarios while handling image files in uploaders

Failed to manipulate with rmagick, may be it is not an image? Original Error: Improper header

Reason: the file you upload is corrupt or it is not a valid image file at all.

You need to handle such scenarios

error1

How to: Validate uploads with Active Record

Standard Active Model validations can be used to ensure a file is uploaded:

mount_uploader :avatar, AvatarUploader
validates_presence_of :avatar

or, when using the mount_on option

mount_uploader :avatar, AvatarUploader, :on => :file_name
validates_presence_of :avatar

So, as you can see, we validate the presence of the uploaded file (not the underlying column on which it’s mounted). This works because the mounted uploader implements the “present?” method used by the validation API.

CarrierWave also supplies additional validations, such as validating the integrity of an uploaded file and validating that the file was successfully processed:

validates_integrity_of :avatar
validates_processing_of :avatar

These two validations are both on by default according to the CarrierWave config.

The validations use translated error messages and can be changed using i18n localization:

en:
  errors:
    messages:
      carrierwave_processing_error: failed to be processed
      carrierwave_integrity_error: is not an allowed file type

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s