Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Glide Bundle Laravel Package

ashleydawson/glide-bundle

View on GitHub
Deep Wiki
Context7

Glide Bundle

Build Status

Add Glide HTTP image processing library to Symfony 2 projects.

Introduction

Glide is an image processing/manipulation/cache for images. It's particularly handy for modifying and storing images on Flysystem filesystems. It leverages the Intervention image manager to do the heavy lifting. The image API is exposed via an HTTP interface allowing you to embed images within your application. For example:

<!-- Embed version of a particular image, truncating the width to 300 pixels -->
<img src="/route/to/image/controller/my-image.jpg?w=300" />

For more information and a better explanation, please read the official Glide docs.

This bundle incorporates all aspects of the Glide library within the Symfony 2 service container - adding features and helpers relative to working with the Glide library within Symfony 2 projects.

Installation

You can install the Glide Bundle via Composer. To do that, simply require the package in your composer.json file like so:

{
    "require": {
        "ashleydawson/glide-bundle": "~1.0"
    }
}

Run composer update to install the package. Then you'll need to register the bundle in your app/AppKernel.php:

$bundles = array(
    // ...
    new AshleyDawson\GlideBundle\AshleyDawsonGlideBundle(),
);

Basic Usage

The most simple example is actually using the glide server to process an image within a controller.

<?php

namespace Acme\AcmeBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;
use League\Flysystem\Adapter\Local;
use League\Flysystem\Filesystem;

class MyController extends Controller
{
    /**
     * @Route("/images/{image_name}.jpg")
     */
    public function showImageAction(Request $request)
    {
        // Filesystems for source and cache
        $sourceFilesystem = new Filesystem(new Local('/path/to/source/dir'));
        $cacheFilesystem = new Filesystem(new Local('/path/to/cache/dir'));
    
        // Create a Glide server
        $glideServer = $this
            ->get('ashleydawson.glide.server_factory')
            ->create($sourceFilesystem, $cacheFilesystem)
        ;
        
        // Return the processed image response
        return $glideServer->getImageResponse($request->get('image_name'), $request->query->all());
    }
}

The example above will create a glide server using a local filesystem for the source and another for the cache. The action then returns an image response built using the image name (in source filesystem) and request containing the manipulation parameters.

Note: You may want to point the cache filesystem at the Symfony cache, app/cache.

Custom Manipulators

Manipulators are services that transform an image in some way. There is a library of manipulators that ships with Glide that provide transformations for size, effects, output, etc.

If you'd like to register your own custom manipulator, simply create one and tag it into the manipulator collection within the Symfony 2 service container. Like so:

<?php

namespace Acme\AcmeBundle\Glide\Manipulator;

use League\Glide\Api\Manipulator\ManipulatorInterface;
use Intervention\Image\Image;
use Symfony\Component\HttpFoundation\Request;

class MyAwesomeManipulator implements ManipulatorInterface
{
    /**
     * {@inheritdoc}
     */
    public function run(Request $request, Image $image)
    {
        if ($request->has('awesome')) {
            // Do something awesome to the image here...    
        }
    
        return $image;
    }
}

Then, in the service container, simply tag your new manipulator as being a part of the glide manipulators collection.

In YAML:


services:

    acme.glide.manipulator.my_awesome_manipulator:
        class: Acme\AcmeBundle\Glide\Manipulator\MyAwesomeManipulator
        tags:
            - { name: ashleydawson.glide.manipulators }

Or, in XML:

<services>
    <service id="acme.glide.manipulator.my_awesome_manipulator" class="Acme\AcmeBundle\Glide\Manipulator\MyAwesomeManipulator">
        <tag name="ashleydawson.glide.manipulators" />
    </service>
</services>

Ok, now we can use this manipulator on an image:

<img src="/route/to/image/controller/my-image.jpg?awesome=foo" />
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
terminal42/code-quality-tools
codifyo/ts-generator-bundle
andydefer/laravel-cluster
testo/fiber
mintobit/jobqueue
a4sex/maintenance-bundle
a4sex/entity-date-update
a4sex/client-identifier
a4sex/base-utilites
a4sex/key-value-storage
a4sex/micro-status
chilldev/dependency-injection-extra
datinglibre/datinglibre-app-api
biberltd/corebundle
bricre/symfony-bundle-test
biberltd/logbundle
dominium/http-adapter-bundle
dominium/google-analytics
a4sex/auto-clean-entity
christhompsontldr/laravel-inky