
Security News
Astral Launches pyx: A Python-Native Package Registry
Astral unveils pyx, a Python-native package registry in beta, designed to speed installs, enhance security, and integrate deeply with uv.
Add width, height, and size to paperclip images.
Paperclip Meta gets image dimensions after post_process_styles
using paperclip's Geometry.from_file
.
Paperclip Meta works with paperclip version 5.x.
Version 2.x works with paperclip version 4.x.
Add paperclip-meta to Gemfile:
gem 'paperclip-meta'
Create migration to add a *_meta column:
class AddAvatarMetaToUsers < ActiveRecord::Migration
def change
add_column :users, :avatar_meta, :text
end
end
Rebuild all thumbnails to populate the meta column if you already have some attachments.
Now you can grab the size from the paperclip attachment:
image_tag user.avatar.url, size: user.avatar.image_size
image_tag user.avatar.url(:medium), size: user.avatar.image_size(:medium)
image_tag user.avatar.url(:thumb), size: user.avatar.image_size(:thumb)
The meta column is simple hash:
style: {
width: 100,
height: 100,
size: 42000
}
This hash will be marshaled and base64 encoded before writing to model attribute.
height
, width
, image_size
and aspect_ratio
methods are provided:
user.avatar.width(:thumb)
=> 100
user.avatar.height(:medium)
=> 200
user.avatar.image_size
=> '60x70'
user.avatar.aspect_ratio
=> 1.5
You can pass the image style to these methods. If a style is not passed, the default style will be used.
https://github.com/thoughtbot/paperclip/wiki/Extracting-image-dimensions
Test:
bundle
bundle exec rake
FAQs
Unknown package
We found that paperclip-meta demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
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.
Security News
Astral unveils pyx, a Python-native package registry in beta, designed to speed installs, enhance security, and integrate deeply with uv.
Security News
The Latio podcast explores how static and runtime reachability help teams prioritize exploitable vulnerabilities and streamline AppSec workflows.
Security News
The latest Opengrep releases add Apex scanning, precision rule tuning, and performance gains for open source static code analysis.