Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

imgproxy-rails

Package Overview
Dependencies
Maintainers
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

imgproxy-rails

  • 0.3.0
  • Rubygems
  • Socket score

Version published
Maintainers
2
Created
Source

imgproxy logo

GH Test GH Test Jruby GH Lint Gem rubydoc.org


Integration of imgproxy.rb with ActiveStorage::Variant API.

Installation

Add to your project:

# Gemfile
gem "imgproxy-rails"

Supported Ruby versions

  • Ruby (MRI) >= 2.7.0
  • JRuby >= 9.3.0

Supported Rails versions

  • Rails >= 6.0.0

Usage

Given the following configuration:

# 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:

# show.erb.html
<%= image_tag Current.user.avatar.variant(resize: "100x100") %>

In dev, it will generate a URL like this:

<img src="http://localhost:3000/rails/active_storage/blobs/proxy/eyJfcmFpbHMiOnsibWVzc2FnZSI6IkJBaHBBWHc9IiwiZXhwIjpudWxsLCJwdXIiOiJibG9iX2lkIn19--0c35e9a616c29da2dfa10a385bae7172526e7961/me.png">

In prod, it will generate a URL like this:

<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:

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

Generating video and PDF previews

If you are an imgproxy Pro user and you want to use it to generate previews for your videos and PDFs, just add their content types to the variable_content_types list:

config.active_storage.variable_content_types << "application/pdf"
config.active_storage.variable_content_types << "video/mp4"
config.active_storage.variable_content_types << "video/mov"
# ...etc

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/imgproxy/imgproxy-rails.

Credits

This gem is generated via new-gem-generator.

License

The gem is available as open source under the terms of the MIT License.

FAQs

Package last updated on 16 Jan 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc