All Projects → teeparham → Paperclip Meta

teeparham / Paperclip Meta

Licence: mit
Adds width, height, and size to paperclip images.

Programming Languages

ruby
36898 projects - #4 most used programming language

Projects that are alternatives of or similar to Paperclip Meta

Idenprof
IdenProf dataset is a collection of images of identifiable professionals. It is been collected to enable the development of AI systems that can serve by identifying people and the nature of their job by simply looking at an image, just like humans can do.
Stars: ✭ 149 (-5.1%)
Mutual labels:  images
Dotfiles
📍 My dotfiles for macOS using Fish/Zsh, Neovim, and Tmux
Stars: ✭ 151 (-3.82%)
Mutual labels:  rails
Weg Li
📸 📝 ✊ weg-li: 1, 2, 3 - Macht die Bahn frei!
Stars: ✭ 156 (-0.64%)
Mutual labels:  rails
Rpush
The push notification service for Ruby.
Stars: ✭ 1,886 (+1101.27%)
Mutual labels:  rails
Rails new
A thoughtfully designed template for building modern Rails apps. Get started in minutes instead of hours 🔥🚀
Stars: ✭ 151 (-3.82%)
Mutual labels:  rails
React Intense
A React component for viewing large images up close 🔍
Stars: ✭ 152 (-3.18%)
Mutual labels:  images
Trado
Trado is a lightweight, easy to use ecommerce platform; designed to allow developers to quickly deploy a premium ecommerce store for their business
Stars: ✭ 149 (-5.1%)
Mutual labels:  rails
Responders
A set of Rails responders to dry up your application
Stars: ✭ 1,925 (+1126.11%)
Mutual labels:  rails
Spina
Spina CMS
Stars: ✭ 1,926 (+1126.75%)
Mutual labels:  rails
Timber Ruby
🌲 Great Ruby logging made easy.
Stars: ✭ 154 (-1.91%)
Mutual labels:  rails
Xcassetpacker
A command line tool for converting a folder of images into an .xcasset package for Xcode
Stars: ✭ 150 (-4.46%)
Mutual labels:  images
Rodauth Rails
Rails integration for Rodauth authentication framework
Stars: ✭ 150 (-4.46%)
Mutual labels:  rails
Ordinare
Ordinare sorts gems in your Gemfile alphabetically
Stars: ✭ 153 (-2.55%)
Mutual labels:  rails
Coverband
Ruby production code coverage collection and reporting (line of code usage)
Stars: ✭ 1,937 (+1133.76%)
Mutual labels:  rails
Spectrum
A client-side image transcoding library.
Stars: ✭ 1,908 (+1115.29%)
Mutual labels:  images
Rack Policy
Rack middleware for the EU ePrivacy Directive compliance in Ruby Web Apps
Stars: ✭ 149 (-5.1%)
Mutual labels:  rails
Ipyplot
IPyPlot is a small python package offering fast and efficient plotting of images inside Python Notebooks. It's using IPython with HTML for faster, richer and more interactive way of displaying big numbers of images.
Stars: ✭ 152 (-3.18%)
Mutual labels:  images
Hound
Automated code review for GitHub pull requests.
Stars: ✭ 1,904 (+1112.74%)
Mutual labels:  rails
Snpr
The sources of the openSNP website
Stars: ✭ 155 (-1.27%)
Mutual labels:  rails
Rawloader
rust library to extract the raw data and some metadata from digital camera images
Stars: ✭ 153 (-2.55%)
Mutual labels:  images

Paperclip Meta

Gem Version Build Status

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 and 6.x.

Version 2.x works with paperclip version 4.x.

Setup

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)

Internals

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.

Alternatives

https://github.com/thoughtbot/paperclip/wiki/Extracting-image-dimensions

Development

Test:

bundle
bundle exec rake
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].