GithubHelp home page GithubHelp logo

shrinerb / shrine-imgix Goto Github PK

View Code? Open in Web Editor NEW
13.0 2.0 4.0 40 KB

Imgix integration for Shrine

Home Page: https://www.imgix.com/

License: MIT License

Ruby 100.00%
shrine imgix storage on-the-fly processing

shrine-imgix's Introduction

Shrine::Storage::Imgix

Provides Imgix integration for Shrine.

Imgix is a service for processing images on the fly, and works with files stored on external services such as AWS S3 or Google Cloud Storage.

Installation

gem "shrine-imgix"

Configuring

Load the imgix plugin with Imgix client settings:

Shrine.plugin :imgix, client: {
  host:             "your-subdomain.imgix.net",
  secure_url_token: "abc123",
}

You can also pass in an Imgix::Client object directly:

require "imgix"

imgix_client = Imgix::Client.new(
  host:             "your-subdomain.imgix.net",
  secure_url_token: "abc123",
)

Shrine.plugin :imgix, client: imgix_client

Path prefix

If you've configured a "Path Prefix" on your Imgix source, and you also have :prefix set on your Shrine storage, you'll need tell the imgix plugin to exclude the storage prefix from generated URLs:

Shrine.plugin :imgix, client: ..., prefix: false

Usage

You can generate an Imgix URL for a Shrine::UploadedFile object by calling #imgix_url:

photo.image.imgix_url(w: 150, h: 200, fit: "crop")
#=> "http://my-subdomain.imgix.net/943kdfs0gkfg.jpg?w=150&h=200&fit=crop"

See the Imgix docs for all available URL options.

Rails

If you're using imgix-rails and want to use the ix_* helpers, you can use #imgix_id to retrieve the Imgix path:

<%= ix_image_tag photo.image.imgix_id, url_params: { w: 300, h: 500, fit: "crop" } %>

Purging

If you want images to be automatically purged from Imgix on deletion, you can set :purge to true:

Shrine.plugin :imgix, client: ..., purge: true

You can also purge manually with Shrine::UploadedFile#imgix_purge:

photo.image.imgix_purge

Note that purging requires passing the :api_key option to your Imgix client.

Development

You can run the test suite with:

$ bundle exec rake test

License

MIT

shrine-imgix's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

shrine-imgix's Issues

Cloning Object with Shrine/Imgix Attachment using .dup fails

I've got an Object with an attacher using shrine-imgix that uses S3 as the storage backend. When I call .dup on the Object it throws #<NoMethodError: undefined method `>' for nil:NilClass> in the Amazon S3 Library at aws-sdk-s3-1.8.0/lib/aws-sdk-s3/plugins/expect_100_continue.rb.

I get the feeling that shrine-imgix should be defining its own version of the copy method but I can't quite seem to figure out what should be in there. Stack trace is below.

File "/app/vendor/bundle/ruby/2.4.0/gems/aws-sdk-s3-1.5.0/lib/aws-sdk-s3/plugins/expect_100_continue.rb" line 18 in call
File "/app/vendor/bundle/ruby/2.4.0/gems/aws-sdk-s3-1.5.0/lib/aws-sdk-s3/plugins/bucket_dns.rb" line 33 in call
File "/app/vendor/bundle/ruby/2.4.0/gems/aws-sdk-core-3.6.0/lib/aws-sdk-core/rest/handler.rb" line 8 in call
File "/app/vendor/bundle/ruby/2.4.0/gems/aws-sdk-core-3.6.0/lib/aws-sdk-core/plugins/user_agent.rb" line 13 in call
File "/app/vendor/bundle/ruby/2.4.0/gems/aws-sdk-core-3.6.0/lib/seahorse/client/plugins/endpoint.rb" line 45 in call
File "/app/vendor/bundle/ruby/2.4.0/gems/aws-sdk-core-3.6.0/lib/aws-sdk-core/plugins/param_validator.rb" line 24 in call
File "/app/vendor/bundle/ruby/2.4.0/gems/aws-sdk-core-3.6.0/lib/seahorse/client/plugins/raise_response_errors.rb" line 14 in call
File "/app/vendor/bundle/ruby/2.4.0/gems/aws-sdk-s3-1.5.0/lib/aws-sdk-s3/plugins/sse_cpk.rb" line 22 in call
File "/app/vendor/bundle/ruby/2.4.0/gems/aws-sdk-s3-1.5.0/lib/aws-sdk-s3/plugins/dualstack.rb" line 26 in call
File "/app/vendor/bundle/ruby/2.4.0/gems/aws-sdk-s3-1.5.0/lib/aws-sdk-s3/plugins/accelerate.rb" line 35 in call
File "/app/vendor/bundle/ruby/2.4.0/gems/aws-sdk-core-3.6.0/lib/aws-sdk-core/plugins/jsonvalue_converter.rb" line 20 in call
File "/app/vendor/bundle/ruby/2.4.0/gems/aws-sdk-core-3.6.0/lib/aws-sdk-core/plugins/idempotency_token.rb" line 17 in call
File "/app/vendor/bundle/ruby/2.4.0/gems/aws-sdk-core-3.6.0/lib/aws-sdk-core/plugins/param_converter.rb" line 24 in call
File "/app/vendor/bundle/ruby/2.4.0/gems/aws-sdk-core-3.6.0/lib/aws-sdk-core/plugins/response_paging.rb" line 10 in call
File "/app/vendor/bundle/ruby/2.4.0/gems/aws-sdk-core-3.6.0/lib/seahorse/client/plugins/response_target.rb" line 23 in call
File "/app/vendor/bundle/ruby/2.4.0/gems/aws-sdk-core-3.6.0/lib/seahorse/client/request.rb" line 70 in send_request
File "/app/vendor/bundle/ruby/2.4.0/gems/aws-sdk-s3-1.5.0/lib/aws-sdk-s3/client.rb" line 5335 in put_object
File "/app/vendor/bundle/ruby/2.4.0/gems/aws-sdk-s3-1.5.0/lib/aws-sdk-s3/object.rb" line 876 in put
File "/app/vendor/bundle/ruby/2.4.0/gems/shrine-2.8.0/lib/shrine/storage/s3.rb" line 397 in put
File "/app/vendor/bundle/ruby/2.4.0/gems/shrine-2.8.0/lib/shrine/storage/s3.rb" line 245 in upload
File "/app/vendor/bundle/ruby/2.4.0/gems/shrine-imgix-0.4.0/lib/shrine/storage/imgix.rb" line 52 in upload
File "/app/vendor/bundle/ruby/2.4.0/gems/shrine-2.8.0/lib/shrine.rb" line 330 in copy
File "/app/vendor/bundle/ruby/2.4.0/gems/shrine-2.8.0/lib/shrine.rb" line 319 in put
File "/app/vendor/bundle/ruby/2.4.0/gems/shrine-2.8.0/lib/shrine/plugins/upload_options.rb" line 32 in put
File "/app/vendor/bundle/ruby/2.4.0/gems/shrine-2.8.0/lib/shrine.rb" line 303 in _store
File "/app/vendor/bundle/ruby/2.4.0/gems/shrine-2.8.0/lib/shrine.rb" line 233 in store
File "/app/vendor/bundle/ruby/2.4.0/gems/shrine-2.8.0/lib/shrine/plugins/hooks.rb" line 95 in block in store
File "/app/vendor/bundle/ruby/2.4.0/gems/shrine-2.8.0/lib/shrine/plugins/hooks.rb" line 101 in around_store
File "/app/vendor/bundle/ruby/2.4.0/gems/shrine-2.8.0/lib/shrine/plugins/hooks.rb" line 95 in store
File "/app/vendor/bundle/ruby/2.4.0/gems/shrine-2.8.0/lib/shrine/plugins/logging.rb" line 86 in block in store
File "/app/vendor/bundle/ruby/2.4.0/gems/shrine-2.8.0/lib/shrine/plugins/logging.rb" line 101 in block in log
File "/app/vendor/bundle/ruby/2.4.0/gems/shrine-2.8.0/lib/shrine/plugins/logging.rb" line 161 in benchmark
File "/app/vendor/bundle/ruby/2.4.0/gems/shrine-2.8.0/lib/shrine/plugins/logging.rb" line 101 in log
File "/app/vendor/bundle/ruby/2.4.0/gems/shrine-2.8.0/lib/shrine/plugins/logging.rb" line 86 in store
File "/app/vendor/bundle/ruby/2.4.0/gems/shrine-2.8.0/lib/shrine/plugins/rack_file.rb" line 62 in store
File "/app/vendor/bundle/ruby/2.4.0/gems/shrine-2.8.0/lib/shrine.rb" line 211 in upload
File "/app/vendor/bundle/ruby/2.4.0/gems/shrine-2.8.0/lib/shrine/plugins/hooks.rb" line 56 in block in upload
File "/app/vendor/bundle/ruby/2.4.0/gems/shrine-2.8.0/lib/shrine/plugins/hooks.rb" line 62 in around_upload
File "/app/vendor/bundle/ruby/2.4.0/gems/shrine-2.8.0/lib/shrine/plugins/hooks.rb" line 56 in upload
File "/app/vendor/bundle/ruby/2.4.0/gems/shrine-2.8.0/lib/shrine/plugins/rack_file.rb" line 56 in upload
File "/app/vendor/bundle/ruby/2.4.0/gems/shrine-2.8.0/lib/shrine.rb" line 635 in store!
File "/app/vendor/bundle/ruby/2.4.0/gems/shrine-2.8.0/lib/shrine/plugins/copy.rb" line 40 in copy
File "/app/vendor/bundle/ruby/2.4.0/gems/shrine-2.8.0/lib/shrine/plugins/copy.rb" line 27 in initialize_copy
File "/app/vendor/bundle/ruby/2.4.0/gems/activerecord-5.1.4/lib/active_record/core.rb" line 411 in initialize_dup
File "/app/vendor/bundle/ruby/2.4.0/gems/activerecord-5.1.4/lib/active_record/core.rb" line 411 in initialize_dup
File "/app/vendor/bundle/ruby/2.4.0/gems/activerecord-5.1.4/lib/active_record/inheritance.rb" line 230 in initialize_dup
File "/app/vendor/bundle/ruby/2.4.0/gems/activemodel-5.1.4/lib/active_model/validations.rb" line 283 in initialize_dup
File "/app/vendor/bundle/ruby/2.4.0/gems/activerecord-5.1.4/lib/active_record/attribute_methods/dirty.rb" line 58 in initialize_dup
File "/app/vendor/bundle/ruby/2.4.0/gems/activerecord-5.1.4/lib/active_record/timestamp.rb" line 51 in initialize_dup
File "/app/vendor/bundle/ruby/2.4.0/gems/activerecord-5.1.4/lib/active_record/associations.rb" line 278 in initialize_dup
File "/app/vendor/bundle/ruby/2.4.0/gems/activerecord-5.1.4/lib/active_record/aggregations.rb" line 8 in initialize_dup
File "/app/app/jobs/copy_job.rb", line 23 in dup

Error in Ruby 3

Due to the kwargs changes, we are getting this:

ArgumentError: wrong number of arguments (given 1, expected 0)
from /home/rtxde/.local/share/rtx/installs/ruby/3.1.4/lib/ruby/gems/3.1.0/gems/shrine-imgix-0.5.2/lib/shrine/plugins/imgix.rb:22:in `imgix_url'

When passing in:

Image.first.file.imigx_url({w: 200})

imgix Legacy API Deprecation

Following the imgix deprecation announcement for the legacy API, imgix is scheduled to deprecate legacy endpoints by March 31rst, 2021.

This deprecation affects the following endpoints:

One of these endpoints was detected in this repository. To ensure that API calls to imgix do not fail, it's crucial to migrate to the new imgix API by following this guide:
https://docs.imgix.com/setup/legacy-api-migration-guide

Note that this concerns only the endpoints aforementioned endpoints. The rendering API will not be affected.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.