Friday, 15 March 2013

imagemagick - How to resize already uploaded Paperclip images to s3 using reprocess? (Rails) -



imagemagick - How to resize already uploaded Paperclip images to s3 using reprocess? (Rails) -

i have model:

class propertyimage < activerecord::base has_attached_file :picture, storage: :s3, s3_credentials: config['s3'], s3_protocol: (rails.env.development? ? "http": "https"), styles: { thumb: '100x100>', large: '633x460>', medium: '301x240>' } end

i'm using rails (4.0.1), cocaine (0.5.4) , paperclip (3.5.4).

i want migrate old images (with no thumb, big , medium) , resize each, created rake script:

namespace :migrate_images desc "resize images in propertyimage" task start_migration: :environment propertyimage.not_migrated.find_each |pi| imageconverter.perform(pi) end end end

and imageconverter class:

class imageconverter def self.perform(pi) begin pi.picture.reprocess! pi.update_attributes!({migrated: true}) puts "propertyimage [#{pi.id}] has been migrated." rescue exception => e puts "propertyimage [#{pi.id}] has error. #{e}" end end end

now when run script maintain getting next error:

⇒ bundle exec rake migrate_images:start_migration [deprecated] i18n.enforce_available_locales default true in future. if want skip validation of locale can set i18n.enforce_available_locales = false avoid message. propertyimage [11] has error. validation failed: image paperclip::errors::notidentifiedbyimagemagickerror, image paperclip::errors::notidentifiedbyimagemagickerror, image paperclip::errors::notidentifiedbyimagemagickerror propertyimage [12] has error. validation failed: image paperclip::errors::notidentifiedbyimagemagickerror, image paperclip::errors::notidentifiedbyimagemagickerror, image paperclip::errors::notidentifiedbyimagemagickerror

please note read similar articles , added next end of application.rb:

paperclip.options[:command_path] = "/usr/local/bin/identify"

and made sure have imagemagick installed:

⇒ brew install imagemagick warning: have outdated version of /usr/bin/install_name_tool installed. cause binary bundle installations fail. can happen if install osx-gcc-installer or railsinstaller. restore it, must reinstall os x or restore binary os packages. warning: imagemagick-6.8.9-7 installed

any help highly appreciated.

please note if seek reproduce problem using rails console:

>> p = property.find(93746) >> p.property_images.each |pi| ?> pi.picture.reprocess! >> end propertyimage load (1.4ms) select "property_images".* "property_images" "property_images"."invalid_image" = 'f' , "property_images"."property_id" = $1 order "property_images"."apartment_main" desc [["property_id", 93746]] [paperclip] copying /property_images/pictures/000/325/476/original/722952f7-4cd4-47bb-bdcf-c7411c9d6021.jpg local file /var/folders/g8/3v37gc0x16b313mvf7464qtc0000gn/t/dfe10026af3ac1b8cc5c94f00437092020141027-6352-12gmkmc.jpg [aws s3 200 1.212736 0 retries] get_object(:bucket_name=>"my_bucket_development",:key=>"property_images/pictures/000/325/476/original/722952f7-4cd4-47bb-bdcf-c7411c9d6021.jpg") command :: identify -format '%wx%h,%[exif:orientation]' '/var/folders/g8/3v37gc0x16b313mvf7464qtc0000gn/t/dfe10026af3ac1b8cc5c94f00437092020141027-6352-12gmkmc.jpg[0]' 2>/dev/null [paperclip] error received while processing: #<paperclip::errors::notidentifiedbyimagemagickerror: paperclip::errors::notidentifiedbyimagemagickerror> command :: identify -format '%wx%h,%[exif:orientation]' '/var/folders/g8/3v37gc0x16b313mvf7464qtc0000gn/t/dfe10026af3ac1b8cc5c94f00437092020141027-6352-12gmkmc.jpg[0]' 2>/dev/null [paperclip] error received while processing: #<paperclip::errors::notidentifiedbyimagemagickerror: paperclip::errors::notidentifiedbyimagemagickerror> command :: identify -format '%wx%h,%[exif:orientation]' '/var/folders/g8/3v37gc0x16b313mvf7464qtc0000gn/t/dfe10026af3ac1b8cc5c94f00437092020141027-6352-12gmkmc.jpg[0]' 2>/dev/null [paperclip] error received while processing: #<paperclip::errors::notidentifiedbyimagemagickerror: paperclip::errors::notidentifiedbyimagemagickerror> [paperclip] saving /property_images/pictures/000/325/476/original/722952f7-4cd4-47bb-bdcf-c7411c9d6021.jpg [aws s3 200 0.293473 0 retries] put_object(:acl=>:public_read,:bucket_name=>"my_bucket_development",:content_length=>0,:content_type=>"image/jpeg",:data=>paperclip::attachmentadapter: 722952f7-4cd4-47bb-bdcf-c7411c9d6021.jpg,:key=>"property_images/pictures/000/325/476/original/722952f7-4cd4-47bb-bdcf-c7411c9d6021.jpg") (0.2ms) begin (0.2ms) rollback

make sure format trying upload supported imagemagick on server using.

to create sure of this, utilize command:

convert -list format

if format trying upload paperclip not in list, need install libraries needed , reinstall/recompile imagemagick.

here given illustration of how on unix machine. install jpg library, used command:

yum install libjpeg libjpeg-devel

how install library , reinstall/recompile imagemagick depends on os utilize , on image format need.

ruby-on-rails imagemagick paperclip

No comments:

Post a Comment