Code Monkey home page Code Monkey logo

resizer's Introduction

Resizer

Simple image resizing bundle for Laravel PHP framework.

This bundle will allow you to resize an uploaded image or any image from the file system with ease. Supported image types are: JPG/JPEG, PNG, GIF.

Installation

Install Resizer using artisan:

php artisan bundle:install resizer

Then in your application/bundles.php file, add the following line to load Resizer automatically:

return array(
    'resizer' => array( 'auto' => true )
);

Or without the 'auto' => true to load it on demand:

return array(
    'resizer'
);

Usage

In your view files, you'd add a file input element.

<?php Input::file('picture') ?>

In your routes.php file or in any of your controller files, you can start the Resizer bundle if you haven't set it to auto-load by calling:

Bundle::start('resizer');

Then you can start resizing your images by simply calling:

Resizer::open( mixed $file )
    ->resize( int $width , int $height , string 'exact, portrait, landscape, auto or crop' )
    ->save( string 'path/to/file.jpg' , int $quality );

Example

Route::post('image/update', function() {
    $img = Input::file('picture');
    
    // Save a thumbnail
    $success = Resizer::open( $img )
        ->resize( 200 , 200 , 'crop' )
        ->save( 'images/my-new-filename.jpg' , 90 );
    
    if ( $success ) {
        return 'woohoo';
    } else {
        return 'lame';
    }
});

Credits

The image resize class was originally written in a tutorial by Jarrod Oberto on NetTuts+. I only modified it to use Laravel's File class, updated the coding style, added comments throughout the class file and turned it into a Laravel bundle.

Enjoy.

resizer's People

Contributors

anahkiasen avatar joshstrange avatar maikeldaloo avatar

Stargazers

 avatar

Watchers

 avatar  avatar  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.