Giter VIP home page Giter VIP logo

laravel-media-toolbox's Introduction

Novius Media Toolbox for Laravel

Travis Packagist Release Licence

Optimize your pictures on-the-fly! ๐Ÿ›ซ

Requirements

Laravel >= 8.0

NOTE: These instructions are for Laravel >= 8.0. If you are using prior version, please see the previous version's docs.

Installation

composer require novius/laravel-media-toolbox

Then, you must publish and run the migrations to create the language_lines table:

php artisan vendor:publish --provider="Novius\MediaToolbox\MediaToolboxServiceProvider" --tag="migrations"
php artisan migrate

Then add this to config/app.php:

// in 'aliases' => [ ... ]
'Medt' => Novius\MediaToolbox\Support\MediaToolbox::class,

Use

In a view:

<!-- This will change the height proportionaly, in order to keep the aspect -->
<img src="{{ Medt::asset('images/hello.png')->width(150) }}">

<!-- It works as well with external pictures. Setting the ratio will force
     previously defined dimensions and change the remaining ones, here the height -->
<img src="{{ Medt::asset('https://example.com/images/logo.png')->width(500)->ratio(16/9) }}">

<!-- fit('cover') is the default behavior. You can just omit it -->
<img src="{{ Medt::asset($user->getPicture())->size(140, 200)->fit('cover') }}">
<img src="{{ Medt::asset($user->getPicture())->size([140, 200])->fit('stretch') }}">

<!-- This will output a jpg with 75% quality.
     Lower number makes smaller files. Minimum is 1, max is 100 -->
<img src="{{ Medt::asset('images/something.gif')->quality(75) }}">

SEO Friendly

You can specify a name for your filename (value will be converted to slug) :

Usage in a view:

<img src="{{ Medt::asset('images/hello.png')->quality(90)->name('my image') }}">

Configure

Publish the config file:

php artisan vendor:publish --provider="Novius\MediaToolbox\MediaToolboxServiceProvider"

Edit config/mediatoolbox.php.

Clearing the cache manually

php artisan cache:clear

Purge expired medias

In your app/Console/Kernel.php file, you should register a daily job to purge expired medias :

protected function schedule(Schedule $schedule)
{
    $schedule->command('media-toolbox:purge-expired')
        ->daily();
}

By default, media is stale considered after 1 week. You can override this value in configuration file with `expire key.

Lint

Run php-cs with:

composer run-script lint

Contributing

Contributions are welcome! Leave an issue on Github, or create a Pull Request.

laravel-media-toolbox's People

Contributors

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