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

active_storage-blurhash

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

active_storage-blurhash

  • 0.1.1
  • Rubygems
  • Socket score

Version published
Maintainers
1
Created
Source

ActiveStorage::Blurhash

A blurhash integration for images stored in ActiveStorage.

Motivation

Elimination of layout shift and speeding up First/Largest Contentful Paint are among the primary goals for improving Core Web Vitals. For both scenarios, lazy loading images while displaying a temporary Blurhash before swapping it out for the actual image is a great way to enhance the loading experience and perceived performance.

Usage

Suppose we have a simple Person model containing an avatar attachment:

class Person < ApplicationRecord
  has_one_attached :avatar
end

Simply swap out image_tag for blurhash_image_tag when displaying it:

<%= blurhash_image_tag person.avatar %>

This will create a wrapper <div> containing a <canvas> that is going to be painted with the respective blurhash.

Make sure to run the install generator and backfill any existing attachments (see below). New attachments should be automatically analyzed to include the blurhash metadata.

Installation

Add this line to your application's Gemfile:

gem "active_storage-blurhash"

And then execute:

$ bundle

Install the JavaScript packages and blurhash snippet:

$ bin/rails g active_storage:blurhash:install

Backfilling

Chances are you already have a large assortment of ActiveStorage attachments. In this case, we can help you out with a backfill rake task that re-analyzes all existing image blobs:

$ bin/rails active_storage_blurhash:backfill

If you want to throttle it, you can change the batch size using the BATCH_SIZE environment variable (default is 1000):

$ BATCH_SIZE=50 bin/rails active_storage_blurhash:backfill

Note that for each blob an AnalyzeJob will be appended to your job processor queue.

License

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

Other gems & packages

  • avo - Build Content management systems with Ruby on Rails
  • class_variants - Easily configure styles and apply them as classes. Very useful when you're implementing Tailwind CSS components and call them with different states.
  • stimulus-confetti - The easiest way to add confetti to your StimulusJS app

Try Avo ⭐️

If you enjoyed this gem try out Avo. It helps developers build internal tools, admins, CMSes, CRMs, and any other type of business apps 10x faster on top of Ruby on Rails.

FAQs

Package last updated on 22 Aug 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