GithubHelp home page GithubHelp logo

image's Introduction

Image

Image manipulation via URLs for Laravel. It provides a URL interface, while the manipulations themselves are done by Intervention.

The manipulated files are stored at the requested URL so the manipulation won't be repeated, but the file will directly be served by your web server.

This package is heavily inspired by folklore/image.

Installation

composer require glaivepro/image

Currently this package does not publish any config, but the manipulations are done by intervention. In case you need to change the driver to imagick, you should configure intervention.

Usage

Let us consider an image that's publicly accessible as example.com/img/some.jpg.

This package will let you get a downsized and cropped version of this file via the URL example.com/img/some-image(120x150).jpg. The manipulated image will be stored in the img directory as some-image(120x150).jpg so that the next request to example.com/img/some-image(120x150).jpg will be handled by your web server providing the stored file.

If you want to downsize, but keep the aspect ratio, skip one of the dimensions:

  • example.com/img/some-image(200x_).jpg — constrain width
  • example.com/img/some-image(_x90).jpg — constrain height

Few other manipulations are available as well:

  • example.com/img/some-image(blur).jpg
  • example.com/img/some-image(blur(10)).jpg
  • example.com/img/some-image(pixelate(12)).jpg
  • example.com/img/some-image(resize(120,140)).jpg — resizing without cropping
  • example.com/img/some-image(100x200-pixelate(10)).jpg
  • example.com/img/some-image(resize(120,140)-blur-pixelate(12)).jpg

Generating URLs

The simple (size constraining) URIs can be generated via our facade:

$uri = GPImage::url('img/some-image.jpg', 120, 150);
// $uri is 'img/some-image-image(120x150).jpg'

Note The method is named url for compatibility with folklore/image. Even though this is not intended as a drop-in replacement, this case will be such if you redefine Image facade alias to point to GlaivePro\Image\GPImage.

Full URLs can be generated via the asset method:

$url = GPImage::asset('img/some-image.jpg', 120, 150);
// $url is 'https://example.com/img/some-image-image(120x150).jpg'

More complex URIs can be generated using the stringable Uri class:

use GlaivePro\Image\Uri;

$uri = new Uri('pic.jpg');
$uri->size(20, 400);

(string) $uri; // 'pic-image(20x400).jpg'

Instances of Uri can also be produced by the url and asset methods of the GPImage facade:

GPImage::asset('pic.jpg')->pixelate(12)->blur(10)->resize(100, 200);
// https://example.com/pic-image(pixelate(12)-blur(10)-resize(100,200)).jpg

Custom filters

You can register your own filters that will receive the intervention instance and any arguments which you can then handle as needed:

// Called via 'somepic-image(simplefilter).jpg'
GPImage::filter('simplefilter', fn ($image) => $image->anyInterventionMethod());

// Called via 'somepic-image(complexfilter(10,20))'
GPImage::filter('complexfilter', function($image, $arg1, $arg2) {
	$tempArg = $arg1 * 2;
	$image->someInterventionMethod($tempArg, $arg1);
	$image->someOtherInterventionMethod();
});

image's People

Contributors

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