Skip to content

Latest commit

 

History

History
71 lines (52 loc) · 1.49 KB

README.md

File metadata and controls

71 lines (52 loc) · 1.49 KB

Imgix

Super simple wrapper for the imgix.net API.

Installation

Add this line to your application's Gemfile:

gem 'imgix'

And then execute:

$ bundle install

Or install it yourself as:

$ gem install imgix

Usage

Basic configuration in the model (currently only supports :h, :w, :crop, :fit, and :bg)

class User < ActiveRecord::Base
	has_imgix_attachment :photo,
	  :subdomain  => "demo",
	  :prefix     => "avatars",
	  :default    => "default.png",
	  :styles =>  {
	    :small  => {
	      :h    => 32,
	      :w    => 32,
	      :crop => "faces",
	      :fit  => "crop"
	    },
	    :medium => {
	      :h    => 64,
	      :w    => 64,
	      :crop => "faces",
	      :fit  => "crop"
	    },
	    :large  => {
	      :h    => 96,
	      :w    => 96,
	      :crop => "faces",
	      :fit  => "crop"
	    }
	  }
end

Retrieve the original image

@user.photo.url
> "http://demo.imgix.net/avatars/filename.jpg"

Retrieve a specific style

@user.photo.url(:medium)
> "http://demo.imgix.net/avatars/filename.jpg?crop=faces&fit=crop&h=64&w=64"

Generate an image tag

imgix_tag(@user.photo, "medium", :alt => "test photo")
> "<img src="http://demo.imgix.net/avatars/filename.jpg?crop=faces&fit=crop&h=64&w=64" alt="test photo" />"

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request