Rails LoadError Generating image variants require the image_processing gem

Updated: 

Troubleshoot Rails LoadError for image variant generation. Learn how to install and use the image_processing gem in your Rails application.

This lesson is from Full Stack Rails Mastery.

If you try to add and save an image inside the Trix editor, you might run into this error:

09:47:11 web.1  | LoadError (Generating image variants require the image_processing gem. Please add `gem 'image_processing', '~> 1.2'` to your Gemfile.): 

The first (obvious) thing to check is if you have installed the image_processing gem.

If you haven't, then install it by running:
bundle add image_processing

Then restart the Rails server and the error should be fixed. Restarting the Rails server can also fix the error if you already had the gem installed but still got the error.

The full error stack trace looks like this:

09:47:11 web.1  | LoadError (Generating image variants require the image_processing gem. Please add `gem 'image_processing', '~> 1.2'` to your Gemfile.):
09:47:11 web.1  |   
09:47:11 web.1  | activestorage (7.1.3) lib/active_storage/transformers/image_processing_transformer.rb:6:in `rescue in <main>'
09:47:11 web.1  | activestorage (7.1.3) lib/active_storage/transformers/image_processing_transformer.rb:3:in `<main>'
09:47:11 web.1  | bootsnap (1.13.0) lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require'
09:47:11 web.1  | bootsnap (1.13.0) lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require'
09:47:11 web.1  | zeitwerk (2.6.12) lib/zeitwerk/kernel.rb:38:in `require'
09:47:11 web.1  | activestorage (7.1.3) app/models/active_storage/variation.rb:85:in `transformer'
09:47:11 web.1  | activestorage (7.1.3) app/models/active_storage/variation.rb:58:in `block in transform'
09:47:11 web.1  | activesupport (7.1.3) lib/active_support/notifications.rb:206:in `block in instrument'
09:47:11 web.1  | activesupport (7.1.3) lib/active_support/notifications/instrumenter.rb:58:in `instrument'
09:47:11 web.1  | activesupport (7.1.3) lib/active_support/notifications.rb:206:in `instrument'
09:47:11 web.1  | activestorage (7.1.3) app/models/active_storage/variation.rb:57:in `transform'
09:47:11 web.1  | activestorage (7.1.3) app/models/active_storage/variant_with_record.rb:49:in `block in transform_blob'
09:47:11 web.1  | activestorage (7.1.3) lib/active_storage/downloader.rb:15:in `block in open'
09:47:11 web.1  | activestorage (7.1.3) lib/active_storage/downloader.rb:24:in `open_tempfile'
09:47:11 web.1  | activestorage (7.1.3) lib/active_storage/downloader.rb:12:in `open'
09:47:11 web.1  | activestorage (7.1.3) lib/active_storage/service.rb:92:in `open'
09:47:11 web.1  | activestorage (7.1.3) app/models/active_storage/blob.rb:290:in `open'
09:47:11 web.1  | activestorage (7.1.3) app/models/active_storage/variant_with_record.rb:48:in `transform_blob'
09:47:11 web.1  | activestorage (7.1.3) app/models/active_storage/variant_with_record.rb:44:in `process'
09:47:11 web.1  | activestorage (7.1.3) app/models/active_storage/variant_with_record.rb:19:in `processed'
09:47:11 web.1  | activestorage (7.1.3) app/controllers/active_storage/representations/base_controller.rb:14:in `set_representation'
09:47:11 web.1  | activesupport (7.1.3) lib/active_support/callbacks.rb:403:in `block in make_lambda'
09:47:11 web.1  | activesupport (7.1.3) lib/active_support/callbacks.rb:202:in `block (2 levels) in halting'
09:47:11 web.1  | actionpack (7.1.3) lib/abstract_controller/callbacks.rb:34:in `block (2 levels) in <module:Callbacks>'
09:47:11 web.1  | activesupport (7.1.3) lib/active_support/callbacks.rb:203:in `block in halting'
09:47:11 web.1  | activesupport (7.1.3) lib/active_support/callbacks.rb:598:in `block in invoke_before'
09:47:11 web.1  | activesupport (7.1.3) lib/active_support/callbacks.rb:598:in `each'
09:47:11 web.1  | activesupport (7.1.3) lib/active_support/callbacks.rb:598:in `invoke_before'
09:47:11 web.1  | activesupport (7.1.3) lib/active_support/callbacks.rb:119:in `block in run_callbacks'
09:47:11 web.1  | actiontext (7.1.3) lib/action_text/rendering.rb:23:in `with_renderer'
09:47:11 web.1  | actiontext (7.1.3) lib/action_text/engine.rb:69:in `block (4 levels) in <class:Engine>'
09:47:11 web.1  | activesupport (7.1.3) lib/active_support/callbacks.rb:130:in `instance_exec'
09:47:11 web.1  | activesupport (7.1.3) lib/active_support/callbacks.rb:130:in `block in run_callbacks'
09:47:11 web.1  | activesupport (7.1.3) lib/active_support/callbacks.rb:141:in `run_callbacks'
09:47:11 web.1  | actionpack (7.1.3) lib/abstract_controller/callbacks.rb:258:in `process_action'
09:47:11 web.1  | actionpack (7.1.3) lib/action_controller/metal/rescue.rb:25:in `process_action'
09:47:11 web.1  | actionpack (7.1.3) lib/action_controller/metal/instrumentation.rb:74:in `block in process_action'
09:47:11 web.1  | activesupport (7.1.3) lib/active_support/notifications.rb:206:in `block in instrument'
09:47:11 web.1  | activesupport (7.1.3) lib/active_support/notifications/instrumenter.rb:58:in `instrument'
09:47:11 web.1  | activesupport (7.1.3) lib/active_support/notifications.rb:206:in `instrument'
09:47:11 web.1  | actionpack (7.1.3) lib/action_controller/metal/instrumentation.rb:73:in `process_action'
09:47:11 web.1  | actionpack (7.1.3) lib/action_controller/metal/params_wrapper.rb:261:in `process_action'
09:47:11 web.1  | activerecord (7.1.3) lib/active_record/railties/controller_runtime.rb:32:in `process_action'
09:47:11 web.1  | actionpack (7.1.3) lib/abstract_controller/base.rb:160:in `process'
09:47:11 web.1  | actionview (7.1.3) lib/action_view/rendering.rb:40:in `process'
09:47:11 web.1  | actionpack (7.1.3) lib/action_controller/metal.rb:227:in `dispatch'
09:47:11 web.1  | actionpack (7.1.3) lib/action_controller/metal.rb:309:in `dispatch'
09:47:11 web.1  | actionpack (7.1.3) lib/action_dispatch/routing/route_set.rb:49:in `dispatch'
09:47:11 web.1  | actionpack (7.1.3) lib/action_dispatch/routing/route_set.rb:32:in `serve'
09:47:11 web.1  | actionpack (7.1.3) lib/action_dispatch/journey/router.rb:51:in `block in serve'
09:47:11 web.1  | actionpack (7.1.3) lib/action_dispatch/journey/router.rb:131:in `block in find_routes'
09:47:11 web.1  | actionpack (7.1.3) lib/action_dispatch/journey/router.rb:124:in `each'
09:47:11 web.1  | actionpack (7.1.3) lib/action_dispatch/journey/router.rb:124:in `find_routes'
09:47:11 web.1  | actionpack (7.1.3) lib/action_dispatch/journey/router.rb:32:in `serve'
09:47:11 web.1  | actionpack (7.1.3) lib/action_dispatch/routing/route_set.rb:882:in `call'
09:47:11 web.1  | warden (1.2.9) lib/warden/manager.rb:36:in `block in call'
09:47:11 web.1  | warden (1.2.9) lib/warden/manager.rb:34:in `catch'
09:47:11 web.1  | warden (1.2.9) lib/warden/manager.rb:34:in `call'
09:47:11 web.1  | rack (2.2.8) lib/rack/tempfile_reaper.rb:15:in `call'
09:47:11 web.1  | rack (2.2.8) lib/rack/etag.rb:27:in `call'
09:47:11 web.1  | rack (2.2.8) lib/rack/conditional_get.rb:27:in `call'
09:47:11 web.1  | rack (2.2.8) lib/rack/head.rb:12:in `call'
09:47:11 web.1  | actionpack (7.1.3) lib/action_dispatch/http/permissions_policy.rb:36:in `call'
09:47:11 web.1  | actionpack (7.1.3) lib/action_dispatch/http/content_security_policy.rb:33:in `call'
09:47:11 web.1  | rack (2.2.8) lib/rack/session/abstract/id.rb:266:in `context'
09:47:11 web.1  | rack (2.2.8) lib/rack/session/abstract/id.rb:260:in `call'
09:47:11 web.1  | actionpack (7.1.3) lib/action_dispatch/middleware/cookies.rb:689:in `call'
09:47:11 web.1  | activerecord (7.1.3) lib/active_record/migration.rb:655:in `call'
09:47:11 web.1  | actionpack (7.1.3) lib/action_dispatch/middleware/callbacks.rb:29:in `block in call'
09:47:11 web.1  | activesupport (7.1.3) lib/active_support/callbacks.rb:101:in `run_callbacks'
09:47:11 web.1  | actionpack (7.1.3) lib/action_dispatch/middleware/callbacks.rb:28:in `call'
09:47:11 web.1  | actionpack (7.1.3) lib/action_dispatch/middleware/executor.rb:14:in `call'
09:47:11 web.1  | actionpack (7.1.3) lib/action_dispatch/middleware/actionable_exceptions.rb:16:in `call'
09:47:11 web.1  | actionpack (7.1.3) lib/action_dispatch/middleware/debug_exceptions.rb:29:in `call'
09:47:11 web.1  | web-console (4.2.0) lib/web_console/middleware.rb:132:in `call_app'
09:47:11 web.1  | web-console (4.2.0) lib/web_console/middleware.rb:28:in `block in call'
09:47:11 web.1  | web-console (4.2.0) lib/web_console/middleware.rb:17:in `catch'
09:47:11 web.1  | web-console (4.2.0) lib/web_console/middleware.rb:17:in `call'
09:47:11 web.1  | actionpack (7.1.3) lib/action_dispatch/middleware/show_exceptions.rb:31:in `call'
09:47:11 web.1  | railties (7.1.3) lib/rails/rack/logger.rb:37:in `call_app'
09:47:11 web.1  | railties (7.1.3) lib/rails/rack/logger.rb:24:in `block in call'
09:47:11 web.1  | activesupport (7.1.3) lib/active_support/tagged_logging.rb:135:in `block in tagged'
09:47:11 web.1  | activesupport (7.1.3) lib/active_support/tagged_logging.rb:39:in `tagged'
09:47:11 web.1  | activesupport (7.1.3) lib/active_support/tagged_logging.rb:135:in `tagged'
09:47:11 web.1  | activesupport (7.1.3) lib/active_support/broadcast_logger.rb:240:in `method_missing'
09:47:11 web.1  | railties (7.1.3) lib/rails/rack/logger.rb:24:in `call'
09:47:11 web.1  | sprockets-rails (3.4.2) lib/sprockets/rails/quiet_assets.rb:13:in `call'
09:47:11 web.1  | actionpack (7.1.3) lib/action_dispatch/middleware/remote_ip.rb:92:in `call'
09:47:11 web.1  | actionpack (7.1.3) lib/action_dispatch/middleware/request_id.rb:28:in `call'
09:47:11 web.1  | rack (2.2.8) lib/rack/method_override.rb:24:in `call'
09:47:11 web.1  | rack (2.2.8) lib/rack/runtime.rb:22:in `call'
09:47:11 web.1  | activesupport (7.1.3) lib/active_support/cache/strategy/local_cache_middleware.rb:29:in `call'
09:47:11 web.1  | actionpack (7.1.3) lib/action_dispatch/middleware/server_timing.rb:59:in `block in call'
09:47:11 web.1  | actionpack (7.1.3) lib/action_dispatch/middleware/server_timing.rb:24:in `collect_events'
09:47:11 web.1  | actionpack (7.1.3) lib/action_dispatch/middleware/server_timing.rb:58:in `call'
09:47:11 web.1  | actionpack (7.1.3) lib/action_dispatch/middleware/executor.rb:14:in `call'
09:47:11 web.1  | actionpack (7.1.3) lib/action_dispatch/middleware/static.rb:25:in `call'
09:47:11 web.1  | rack (2.2.8) lib/rack/sendfile.rb:110:in `call'
09:47:11 web.1  | actionpack (7.1.3) lib/action_dispatch/middleware/host_authorization.rb:141:in `call'
09:47:11 web.1  | railties (7.1.3) lib/rails/engine.rb:536:in `call'
09:47:11 web.1  | puma (5.6.5) lib/puma/configuration.rb:252:in `call'
09:47:11 web.1  | puma (5.6.5) lib/puma/request.rb:77:in `block in handle_request'
09:47:11 web.1  | puma (5.6.5) lib/puma/thread_pool.rb:340:in `with_force_shutdown'
09:47:11 web.1  | puma (5.6.5) lib/puma/request.rb:76:in `handle_request'
09:47:11 web.1  | puma (5.6.5) lib/puma/server.rb:443:in `process_client'
09:47:11 web.1  | puma (5.6.5) lib/puma/thread_pool.rb:147:in `block in spawn_thread'