Giter Site home page Giter Site logo

fastimage_resize's Introduction

FastImage Resize

FastImage Resize is an extremely light solution for resizing images in ruby by using libgd

FastImage Resize will resize gifs, jpegs, and png files.

It uses resampling to get good looking results.

And it doesn’t rely on installing external heavy libraries such as RMagick (which relies on ImageMagick or GraphicsMagick) or ImageScience (which relies on FreeImage).

FastImage Resize uses Libgd, which is commonly available on most unix platforms, including OSX. It is very likely that you already have this software installed on your server.

As its input, FastImage Resize can take a URI, a filename, or an IO object (or anything that responds to :read).
If you do not supply an output filename in the :outfile option, FastImage Resize will return you a Tempfile object. This will be unlinked when it is finalized during garbage collection.

FastImage Resize relies on RubyInline for compiling and managing the C extension code.

Incompatible API change Version 2.0.0 and above

Note that the parameters for version 2.0.0 have changed, the output filename is no longer the second parameter. See the examples.

Examples


  require 'fastimage_resize'

  FastImage.resize("http://stephensykes.com/images/ss.com_x.gif", 100, 20, :outfile=>"my.gif")
  => nil

  outfile = FastImage.resize("nonexistentfile.png", 50, 50)
  =>FastImage::ImageFetchFailure: FastImage::ImageFetchFailure

  outfile = FastImage.resize("afile.png", 50, 150)
  => #<File:/var/folders/vm/vd65y2597xl_by6c73_m9j1h0000gn/T/FastImage20111003-7638-x3l8r7-0.png>
  
  File.open("afile.png", "r") {|f| FastImage.resize(f, 100, 100)}
  => #<File:/var/folders/vm/vd65y2597xl_by6c73_m9j1h0000gn/T/FastImage20111003-7638-y1ofh-0.png>

Giving a zero value for width or height causes the image to scale proportionately.

Installation

First check the requirements section below.

Gem


  gem install fastimage_resize

Rails

Install the gem as above, and for Rails 2 configure it in your environment.rb file as below:


... Rails::Initializer.run do |config| ... config.gem "fastimage_resize" ... end ...

For Rails 3, add this to your Gemfile:


gem 'fastimage_resize'

For any Rails version, you may also need this in your environment.rb so that the rails process puts the compiled C code in a place it can access:


ENV['INLINEDIR'] = RAILS_ROOT + "/tmp"  # for RubyInline

Then you’re off – just use FastImage.resize() in your code as in the examples.

Requirements

  • RubyInline

  gem install RubyInline

  • FastImage

  gem install fastimage

  • Libgd

See http://www.libgd.org/

Libgd is commonly available on most unix platforms, including OSX.

On OSX, if you have macports you can use.


  sudo port install gd2

It is also available in homebrew (search for gd), and fink (try fink install gd2 gd2-bin).

Documentation

http://rdoc.info/projects/sdsykes/fastimage_resize

Caveats

Because of the way that libgd works, gif files that have transparency may not always come through with the transparency perfectly retained.

Tests

You’ll need to ‘gem install fakeweb’ to be able to run the tests

References

Licence

MIT, see file MIT_LICENCE

Author

Stephen Sykes, @sdsykes

fastimage_resize's People

Contributors

keslerm avatar sdsykes avatar

Watchers

 avatar

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.