Giter Club home page Giter Club logo

attachment-on-the-fly's Introduction

Attachment on the Fly

Attachment on the Fly is a module that extends Paperclip by allowing dynamic image resizing without going through ActiveRecord first. This gem can only resize images. If you try to resize a PDF or other attachment, nothing will happen.

Requirements

  • thoughtbot-paperclip gem

  • ImageMagick

Quick Start

Attachment on the Fly is hosted on Gemcutter, so it is recommended that you install the Gemcutter gem before installing Attachment on the Fly.

See gemcutter.org/ for installation instructions. Then:

sudo gem install attachment_on_the_fly

Setup your models the same way you normally do with Paperclip. See github.com/thoughtbot/paperclip for detailed instructions.

Once your attachments are working with Paperclip, add this line to the top of your models:

require “attachment_on_the_fly”

To use, reference the instance of your attachment like this:

<%= my_image_model.attachment.s_640_480 %>

This will output an image path based on your url interpolation and a resized image named S_640_480_your_image_name.jpg (or gif or png).

Usage

Attachment on the Fly can accept three types of inputs: width by height, height proportional, and width proportional.

my_image_model.attachment.s_640_480 will generate a 640x480 pixel image.

my_image_model.attachment.s_640_width will generate an image that is 640 pixels wide and proportionally high based on the original image dimensions.

my_image_model.attachment.s_480_height will generate an image that is 480 pixels high and proportionally wide based on the original image dimensions.

When an image’s instance is first accessed through the s_ method, a new image will be generated according to the image’s path interpolation. Then, every time the image is accessed with the same dimensions, the previously generated image will be used. This allows the flexibility to resize images at will but still be able to cache previously generated images.

Currently, convert’s sharpen is set to 1. If you need to change the sharpness or any other of convert’s command line options, you will need to do so in the final lines of lib/attachment_on_the_fly.rb. We are working on a feature to do this dynamically, but it is not available yet.

Note that, for now, you need to name your model ‘attachment’.

Contributing

If you find this gem useful, please post your comments, bugs, patches and suggestions on our Github site at github.com/drpentode/Attachment-on-the-Fly.

attachment-on-the-fly's People

Contributors

drpentode avatar onsitedev avatar reinaldomendes avatar slash4 avatar timsco avatar torsakch avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

Forkers

vdv

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.