Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ActiveStorage wont crop variants

I'm migrating my rails app from paperclip to ActiveStorage and it just won't accept the crop argument in a variant

this line:

@user.image.variant(crop: [180,135])

cause this error:

Errno::ENOENT (No such file or directory @ rb_sysopen - /var/folders/dd/dy3xgqrs2vv6h97ckrtmrb4m0000gn/T/mini_magick20180526-14598-njz21n.jpg):

activestorage (5.2.0) app/models/active_storage/variant.rb:130:in `initialize'
activestorage (5.2.0) app/models/active_storage/variant.rb:130:in `open'
activestorage (5.2.0) app/models/active_storage/variant.rb:130:in `upload'
activestorage (5.2.0) app/models/active_storage/variant.rb:88:in `block in process'
activestorage (5.2.0) app/models/active_storage/variant.rb:110:in `open_image'
activestorage (5.2.0) app/models/active_storage/variant.rb:85:in `process'
activestorage (5.2.0) app/models/active_storage/variant.rb:53:in `processed'
activestorage (5.2.0) app/controllers/active_storage/representations_controller.rb:12:in `show'

while eg. this works:

@user.image.variant(resize: '180x135')
like image 382
antpaw Avatar asked May 26 '18 21:05

antpaw


1 Answers

For Rails 6.0 users:

object.image.variant(resize_to_fill: [180, 135, { gravity: 'North' }])

I'm writing this for those who like me didn't know how to use options in variants.

like image 200
Pascal Avatar answered Oct 17 '22 16:10

Pascal