0

in my rails Application I have the following code.

    class ProjectImage < ApplicationRecord
      belongs_to :project

      has_many_attached :images do |attachable|
        attachable.variant :thumb, resize_to_limit: [100, 100], saver: { quality: 80 }
        attachable.variant :medium, resize_to_limit: [800, 800], saver: { quality: 75 }
      end
    end

and in gemfile

    gem 'image_processing', '~> 1.2'
    gem 'mini_magick'

Iam getting the following errors like below

/home/dinesh/.rvm/gems/[email protected]_app/gems/image_processing-1.2.0/lib/image_processing/chainable.rb:15:in `saver': wrong number of arguments (given 1, expected 0) (ArgumentError)

in rails console while trying to create thumnail and medium variants of an attached image

  dinesh@DESKTOP-635K3MC:/mnt/c/Workspace/my_app$ rails c
  No executable found at . Will fall back to
  Loading development environment (Rails 7.0.4)
  3.2.0 :001 > require 'image_processing/mini_magick'
  [METRICS]  Completed in 2.4ms | Allocations: 241
  => true
  3.2.0 :002 > image = ProjectImage.last.images.first
    ProjectImage Load (0.7ms)  SELECT `project_images`.* FROM `project_images` ORDER BY `project_images`.`id` DESC LIMIT 1
    ActiveStorage::Attachment Load (60.4ms)  SELECT `active_storage_attachments`.* FROM `active_storage_attachments` WHERE `active_storage_attachments`.`record_id` = 88 AND `active_storage_attachments`.`record_type` = 'ProjectImage' AND `active_storage_attachments`.`name` = 'images' ORDER BY `active_storage_attachments`.`id` ASC LIMIT 1
  [METRICS]  Completed in 126.8ms | Allocations: 14520 | ActiveRecord: 63.8ms (queries: 6)
  => #<ActiveStorage::Attachment:0x00007ff6cfcfc678 id: 144, name: "images", record_type: "ProjectImage", record_id: 88, blob_id: 144, created_at: Wed, 31 Jul 2024 05:17:10.672157000 EDT -04:00>

  3.2.0 :011 > processed = ImageProcessing::MiniMagick
  3.2.0 :012 > .source(image)
  3.2.0 :013 > .resize_to_limit(800, 800)
  3.2.0 :014 > .quality(75)
  3.2.0 :015 > .call(destination: '/tmp/processed_image.jpg')
  /home/dinesh/.rvm/gems/[email protected]_app/gems/image_processing-1.2.0/lib/image_processing/chainable.rb:54:in `branch': wrong number of arguments (given 1, expected 0) (ArgumentError)
  3.2.0 :016 >

  3.2.0 :039 >
  3.2.0 :040 > file = ActiveStorage::Blob.service.send(:path_for, image.key)
  [METRICS]  Completed in 0.2ms | Allocations: 59
  => "/mnt/c/Workspace/my_app/storage/dh/en/dhenjruof4jlv35411oxebu9j0tt"
  3.2.0 :041 >
  3.2.0 :042 > processed = ImageProcessing::MiniMagick
  3.2.0 :043 >   .source(file)
  3.2.0 :044 >   .resize_to_limit(800, 800)
  3.2.0 :045 >   .quality(75)
  3.2.0 :046 >   .call(destination: '/tmp/processed_image.jpg')
  /home/dinesh/.rvm/gems/[email protected]_app/gems/image_processing-1.2.0/lib/image_processing/chainable.rb:54:in `branch': wrong number of arguments (given 1, expected 0) (ArgumentError)
  3.2.0 :047 >

  3.2.0 :047 >
  3.2.0 :048 > include Rails.application.routes.url_helpers
  [METRICS]  Completed in 0.5ms | Allocations: 175
  => Object
  3.2.0 :049 >
  3.2.0 :050 >
  3.2.0 :051 > Rails.application.routes.default_url_options[:host] = 'localhost:3000'
  [METRICS]  Completed in 0.1ms | Allocations: 52
  => "localhost:3000"
  3.2.0 :052 >
  3.2.0 :053 > project_image = ProjectImage.last
    ProjectImage Load (0.4ms)  SELECT `project_images`.* FROM `project_images` ORDER BY `project_images`.`id` DESC LIMIT 1
  [METRICS]  Completed in 1.4ms | Allocations: 217 | ActiveRecord: 0.4ms (queries: 1)
  =>
  #<ProjectImage:0x00007ff6cfbeb7c0
  ...
  3.2.0 :054 > or(image)
  3.2.0 :054 > project_image.images.each do |image|
  3.2.0 :055 >   original_url = url_for(image)
  3.2.0 :056 >   thumbnail_url = url_for(image.variant(:thumb).processed)
  3.2.0 :057 >   medium_url = url_for(image.variant(:medium).processed)
  3.2.0 :058 >
  3.2.0 :059 >   puts "Original: #{original_url}"
  3.2.0 :060 >   puts "Thumbnail: #{thumbnail_url}"
  3.2.0 :061 >   puts "Medium: #{medium_url}"
    ActiveStorage::Attachment Load (0.4ms)  SELECT `active_storage_attachments`.* FROM `active_storage_attachments` WHERE `active_storage_attachments`.`record_id` = 88 AND `active_storage_attachments`.`record_type` = 'ProjectImage' AND `active_storage_attachments`.`name` = 'images'
    ActiveStorage::Blob Load (0.3ms)  SELECT `active_storage_blobs`.* FROM `active_storage_blobs` WHERE `active_storage_blobs`.`id` = 144 LIMIT 1
    ActiveStorage::VariantRecord Load (0.5ms)  SELECT `active_storage_variant_records`.* FROM `active_storage_variant_records` WHERE `active_storage_variant_records`.`blob_id` = 144 AND `active_storage_variant_records`.`variation_digest` = 'ENcXmpHy8uaefOEARzwsAvf/nEc=' LIMIT 1
    Disk Storage (11.1ms) Downloaded file from key: dhenjruof4jlv35411oxebu9j0tt
  /home/dinesh/.rvm/gems/[email protected]_app/gems/image_processing-1.2.0/lib/image_processing/chainable.rb:15:in `saver': wrong number of arguments (given 1, expected 0) (ArgumentError)
  3.2.0 :063 >
  3.2.0 :064 >
3
  • I think you don't need to import the minimagick gem. Commented Jul 31, 2024 at 19:02
  • @BrunoCostanzo i tried without using the minimagic gem than also was having the same issue, than i thought i was missing minimagic gem , and added to the app Commented Jul 31, 2024 at 19:06
  • gem 'image_processing', '~> 1.12', '>= 1.12.2' then bundle install. Commented Jul 31, 2024 at 19:41

1 Answer 1

0

The latest version of Image Processing gem is 1.13.0

Version 1.2.0 has no updates since 6 years ago.

Change this in your Gemfile

gem "image_processing", "~> 1.0"

and then test again, without the Minimagick gem if possible, because the problem doesn't seem related to that.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.