Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
Bakaface committed Aug 6, 2023
1 parent b4645d4 commit d25e442
Showing 1 changed file with 36 additions and 2 deletions.
38 changes: 36 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

# imgproxy-rails

TBD
Integration of [imgproxy.rb](https://github.com/imgproxy/imgproxy.rb) with [ActiveStorage::Variant API](https://api.rubyonrails.org/v5.2.0/classes/ActiveStorage/Variant.html).

## Installation

Expand All @@ -19,9 +19,43 @@ gem "imgproxy-rails"
- Ruby (MRI) >= 2.7.0
- JRuby >= 9.2.9

### Supported Rails versions
- Rails >= 6.0.0

## Usage

TBD
Given the following configuration:

```ruby
# development.rb
config.active_storage.resolve_model_to_route = :rails_storage_proxy

# production.rb
config.active_storage.resolve_model_to_route = :imgproxy_active_storage
```
The following HTML snippet will generate different URLs in dev and prod:

```ruby
# show.erb.html
<%= image_tag Current.user.avatar.variant(resize: "100x100") %>
```
In dev, it will generate a URL like this:
```html
<img src="http://localhost:3000/rails/active_storage/blobs/proxy/eyJfcmFpbHMiOnsibWVzc2FnZSI6IkJBaHBBWHc9IiwiZXhwIjpudWxsLCJwdXIiOiJibG9iX2lkIn19--0c35e9a616c29da2dfa10a385bae7172526e7961/me.png">
```
In prod, it will generate a URL like this:

```html
<img src="https://imgproxy.example.com/8uVB2dYrZVOdG-1tekFjNJZ7s7VHDViXJbu9TcQavQ8/fn:me.png/aHR0cDovL2xvY2Fs/aG9zdDozMDAwL3Jh/aWxzL2FjdGl2ZV9z/dG9yYWdlL2Jsb2Jz/L3Byb3h5L2V5SmZj/bUZwYkhNaU9uc2li/V1Z6YzJGblpTSTZJ/a0pCYUhCQldIYzlJ/aXdpWlhod0lqcHVk/V3hzTENKd2RYSWlP/aUppYkc5aVgybGtJ/bjE5LS0wYzM1ZTlh/NjE2YzI5ZGEyZGZh/MTBhMzg1YmFlNzE3/MjUyNmU3OTYxL21l/LnBuZw">
```

You can also specify imgproxy-specific parameters in `imgproxy_options` attribute. Imgproxy-specific params will take precedence over ones from original API:

```ruby
# height=50 and width=50 will be applied
Current.user.avatar.variant(resize: "100x100", imgproxy_options: { height: 50, width: 50 })
```

## Contributing

Expand Down

0 comments on commit d25e442

Please sign in to comment.