Giter Site home page Giter Site logo

spatie / laravel-glide Goto Github PK

View Code? Open in Web Editor NEW
411.0 16.0 49.0 862 KB

Easily convert images with Glide

Home Page: https://freek.dev/2015/12/easily-convert-images-with-glide/

License: MIT License

PHP 100.00%
laravel php image manipulate glide convert

laravel-glide's Introduction

Easily convert images with Glide

Latest Version run-tests Software License Total Downloads

This package provides an easy to use class to manipulate images. Under the hood it leverages Glide to perform the manipulations.

Here's an example of how the package can be used:

GlideImage::create($pathToImage)
	->modify(['w'=> 50, 'filt'=>'greyscale'])
	->save($pathToWhereToSaveTheManipulatedImage);

Support us

Learn how to create a package like this one, by watching our premium video course:

Laravel Package training

We invest a lot of resources into creating best in class open source packages. You can support us by buying one of our paid products.

We highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using. You'll find our address on our contact page. We publish all received postcards on our virtual postcard wall.

Installation

You can install the package through Composer.

composer require spatie/laravel-glide

In Laravel 5.5 the service provider and facade will automatically get registered. In older versions of the framework just add the service provider and facade in config/app.php file:

'providers' => [
    ...
    Spatie\Glide\GlideServiceProvider::class,
    ...
];

...

'aliases' => [
	...
    'GlideImage' => Spatie\Glide\GlideImageFacade::class,
    ...
]

You can publish the config file of the package using artisan.

php artisan vendor:publish --provider="Spatie\Glide\GlideServiceProvider"

The config file looks like this:

<?php

return [

    /*
     * The driver that will be used to create images. Can be set to gd or imagick.
     */
    'driver' => 'gd',
];

Usage

Here's a quick example that shows how an image can be modified:

GlideImage::create($pathToImage)
	->modify(['w'=> 50, 'filt'=>'greyscale'])
	->save($pathToWhereToSaveTheManipulatedImage);

Take a look at Glide's image API to see which parameters you can pass to the modify-method.

Testing

You can run the tests with:

composer test

Changelog

Please see CHANGELOG for more information what has changed recently.

Previous versions

Previous versions of this package had PHP 5.4 support and the ability to generate images on the fly from an url.

The previous versions are unsupported, but they should still work in your older projects.

Security

If you've found a bug regarding security please mail [email protected] instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please see LICENSE for more information.

laravel-glide's People

Contributors

adrianmrn avatar akoepcke avatar alexvanderbist avatar artemverbo avatar big-shark avatar freekmurze avatar jakoblaegdsmand avatar judereid avatar laravel-shift avatar lukepolo avatar m1guelpf avatar matthiasdewinter avatar nielsvanpach avatar patinthehat avatar rubenvanassche avatar sennik avatar tjoosten avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

laravel-glide's Issues

2.3.0 requires php 7?

Hello,

I get this:

  Problem 1
    - Installation request for spatie/laravel-glide 2.3.0 -> satisfiable by spatie/laravel-glide[2.3.0].
    - spatie/laravel-glide 2.3.0 requires php ^7.0 -> your PHP version (5.6.20) does not satisfy that requirement.
  Problem 2
    - spatie/laravel-medialibrary 3.17.4 requires spatie/laravel-glide ^2.2.4 -> satisfiable by spatie/laravel-glide[2.3.0].
    - spatie/laravel-medialibrary 3.17.4 requires spatie/laravel-glide ^2.2.4 -> satisfiable by spatie/laravel-glide[2.3.0].
    - spatie/laravel-glide 2.3.0 requires php ^7.0 -> your PHP version (5.6.20) does not satisfy that requirement.
    - Installation request for spatie/laravel-medialibrary 3.17.4 -> satisfiable by spatie/laravel-medialibrary[3.17.4].

Maybe some dependencies went up?

Route cache generation not possible due Closure

The following code should just use a Controller:

$this->app['router']->get($glideConfig['baseURL'].'/{all}', function () use ($glideConfig)

Because cache generation may fail now because of laravel-glide :

php artisan route:cache
Route cache cleared!

  [LogicException]
  Unable to prepare route [img/{all}] for serialization. Uses Closure.

Glide update

Can you upgrade the glide version, as the glide version in the composer file is outdated, and I am encountering a lot of issues that have been fixed in the latest version of glide.

Laravel 5.8 / 6 Installation Instructions

Hi, this is a great plugin but I can't get it working in Laravel 5.8. Can you provide some updated installation instructions as the video you created was back in 2015. Many thanks.

file_exists(): open_basedir restriction in effect.

Hey

I'm using glide to do some image manipulations on an uploaded image.
When testing locally, everything works but when we deploy to a combell shared hosting, I get the following error:
file_exists(): open_basedir restriction in effect. File(/data/sites/web/scribblrmtantwerpeu/tmp/phpmkV0Wn/f1b906abc87cd37f44c511f8dd7acc88) is not within the allowed path(s): (/data/sites/web/scribblrmtantwerpeu:/usr/local/php-7.1/lib/php:/usr/bin:/tmp:/data/vendor-scripts:/data/sites/web/disabled:/etc/ssl/certs)

I guess this is trying to check if the file exists in the tmp folder. The problem is that it starts from the basepath, which we don't have access to. The root of our shared hosting in this case is 'scribblrmtantwerpeu'

Any way we can fix this?

Changed the path and the baseURL, still searching in img

Hi, first of all thanks for your package.

I published the config and modified it to adjust to my project, but when I inspect the HTML I see the glide is generating the URL pointing to img, also it can't process a load('folder/img.jpg'), it transforms to folder%2Fimg.jpg.

Do you know how can I solve those problems?

Thanks!

Imagick falling back to GD always

I can confirm that on my php -m imagick is installed properly
I can also use imagick in the terminal.
I have required ext-imagick on my composer.json.
When i try to process an SVG image it fails with this message
Unsupported image type. GD driver is only able to decode JPG, PNG, GIF or WebP files.

weird because in my config/image.php
driver is set to imagick.

I don't know why it still keeps using GD and failing because gd does not support svg

here's the actual file

https://foodat.ph/img/FoodatWhite.svg

imagemagick version 7.0.7-25 imagick pecl 3.4.4

you can check my php.ini here
https://foodat.ph/

thank you

Lumen Support

This is a request. I am working in Lumen but cannot just figure how to get this working. Can you create a package to support Lumen?

[FlySystem Laravel] impossible to create the root directory

Hello everyone !

I'm using your package with these version:

  • Php: 7.4.11
  • Laravel: 8.10.0
  • Extension: Imagick
  • Mysql: 5.7 for macOS

The error:
Capture-d-cran-2020-10-15-14-13-25.png

Capture-d-cran-2020-10-15-14-13-49.png

I don't know { how, what, why } this problem or where they from but I think it on the glide package.

I'have try to fix my problem with this link

But nothing that work, so I'm out of solution.

Imagick SVG background problem

is it a default behavior that the svg image background turns to white?
return $server->getImageResponse($path, request()->all());
sample file : https://foodat.ph/img/FoodatWhite.svg

directly linking the file shows an svg image with a transparent background.
original link : https://s3.ap-southeast-1.amazonaws.com/foodat.ph/public/FoodatWhite.svg

i'm using it in an image tag like so

using getImageResponse
<img src='img/FoodatWhite.svg'></img>
direct link
<img src='https://s3.ap-southeast-1.amazonaws.com/foodat.ph/public/FoodatWhite.svg'></img>

explicitly setting the alpha channel to 0 still don't work
image

img/FoodatWhite.svg?bg=0fff

Thank you

Route caching with Laravel 5

Does this package work with Laravel 5 route caching ?
I see that there is a closure on router->get…

$this->app['router']->get($glideConfig['baseURL'].'/{all}', function () use ($glideConfig) {
…
})

How to cache Image?

I do not want to save the image in any directory and only want to create cache image for some time when user call the Image?

installation error

Hi,
I am using your medialibrary pachage already,
now I need to install laravel-glide
but when i run

composer require spatie/laravel-glide

it gives me following error

Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - spatie/laravel-medialibrary 3.17.2 requires spatie/laravel-glide ^2.2.4 -> satisfiable by spatie/laravel-glide[2.x-dev].
    - spatie/laravel-medialibrary 3.17.2 requires spatie/laravel-glide ^2.2.4 -> satisfiable by spatie/laravel-glide[2.x-dev].
    - spatie/laravel-medialibrary 3.17.2 requires spatie/laravel-glide ^2.2.4 -> satisfiable by spatie/laravel-glide[2.x-dev].
    - Can only install one of: spatie/laravel-glide[3.0.0, 2.x-dev].
    - Installation request for spatie/laravel-glide ^3.0 -> satisfiable by spatie/laravel-glide[3.0.0].
    - Installation request for spatie/laravel-medialibrary == 3.17.2.0 -> satisfiable by spatie/laravel-medialibrary[3.17.2].

Am I doing something wrong?
I am on laravel 5.2

"Signature is missing"

Hi,
I have this error
exception 'League\Glide\Http\SignatureException' with message 'Signature is missing.' in /home/devmg/public_html/laravel/vendor/league/glide/src/Http/Signature.php:43
and I can't figure out what is the problem. Can somebody help me?
I'm using Laravel 4.2 by the way.

Glide version 0.3.0

Hey @freekmurze, thanks so much for putting this library together. I just wanted to let you know that I just released Glide version 0.3.0. I'll be honest, this release has many breaking changes from version 0.2.x. I apologize for that, but I did want to make all significant changes prior to an eventual 1.0 release. You can find the changelog here.

I will note that I designed version 0.3.0 with Laravel 5 in mind. In fact, Taylor was even kind enough to accept a tweak to the new filesystem adapter in Laravel 5 to to allow access to underlying Flysystem driver. This allows you to use the already configured Flysystem instance with Glide. Here is a rough example:

$this->app->singleton('League\Glide\Server', function ($app) {

    $filesystem = $this->app->make('Illuminate\Contracts\Filesystem\Filesystem');

    return League\Glide\ServerFactory::create([
        'source' => $filesystem->getDriver(),
        'cache' => $filesystem->getDriver(),
        'source_path_prefix' => 'path/to/source/images',
        'cache_path_prefix' => 'path/to/image/cache',
    ]);
});

Laravel 5 was also a big reason why I added the new source_path_prefix and cache_path_prefix options. Normally you would just set this when create your Flysystem objects, but since you only have one instance available in Laravel 5 you need a way to set the source and cache paths at the Server level.

You'll also notice that I rearranged the folder structure significantly in this version as well, so there are a bunch of new class names and namespaces. This was a bit painful, but I think it was a good move thinking long term.

Just thought I'd touch base and bring you up to speed on all this! :)

route code

hi , how should i implement code in routes.php to process image?
this is my code but it doesnt work

$server = League\Glide\ServerFactory::create([
    'source' => 'images/offer',
    'cache' => 'images/cache',
]);
Route::match(['get','post'],'img/{other?}', function(\Illuminate\Http\Request $request){
   /$server->outputImage($request);

});

ErrorException in GlideImage.php line 30

After my issue #62 i updated to verion 3.1.0

I have this in my Config
`
return [

/*
 * The driver that will be used to create images. Can be set to gd or imagick.
 */
'driver' => 'gd',

/*
 * Glide will search for images in this directory
 *
 */
'source' => [
    'path' => storage_path('images'),
],

/*
 * The directory Glide will use to store it's cache
 * A .gitignore file will be automatically placed in this directory
 * so you don't accidentally end up committing these images
 *
 */
'cache' => [
    'path' => storage_path('glide/cache'),
],

/*
 * URLs to generated images will start with this string
 *
 */
'baseURL' => 'img',

/*
 * The maximum allowed total image size in pixels
 */
'maxSize' => 2000 * 2000,

/*
 * Glide has a feature to sign each generated URL with
 * a key to avoid the visitors of your site to alter the URL
 * manually
 */
'useSecureURLs' => true,

];
`

I have image Called foot.jpg in Storage/App/Images

<img src="{{ GlideImage::create('foot.jpg')->modify(['w'=> 200, 'filt'=>'greyscale']) }}" />

but i have this error:

erreur_exception

Call to undefined method Spatie\Glide\GlideImage::load()

Hi I Just Downloaded This package and It's not woking I thing many files are missing:

I did all this :
composer require spatie/laravel-glide
And configuration also,

but in the vendor I can't see where is the route config even the laravel-glide.php is empty just the driver gd

I can't see al that config when published. What IM doing wrong ?

fix for L5

Is this going to be fixed for laravel 5?

2.3.1 bugged

Since the latest update from v2 I get this errors:

Internention\Image\Exception\NotSupportedException · GET /img/photos/_270_2101912-Foobarjpg_5735a2cb3519a
Driver () could not be instantiated.

Php 7 required

Packagists show ~14k installs for this package. I'm with a small web-app firm (4 people), and we simply have too much old sites running to port everything to php 7. We'll get there in about 1 year I guess, we have 120 sites running (low traffic).

Our new system is built upon Laravel 5.1, and we like to keep up with new development now. However, getting our vps to php 7 is simply not an option in the nearby future.

We really like this package, and would like to continue using it. I've read tons on the cool new stuff in 7, but for a big package breaking with many people seems like a bad plan!

There is the option of maintaining two branches at the same time. With the Python 2/3 problems, lots of big libraries have tried really hard to be compatible with 2.X and 3.X , none of the big ones did complete dropping of 2.X

Glide Image Api on Laravel-medialibrary

Using Medialibrary, I can successfully modify the media conversions, using setManipulations in my Model file, for instance orientating thumbnail pic of 90 degrees:

//Post.php
public function registerMediaConversions(){
$this->addMediaConversion('thumb')->setManipulations(['or' => 90])->performOnCollections('images');
}

However, I would like to perform this manipulation on the original media itself, not on the conversion.
In order to do that, I tried to modify my upload controller this way:

//UploadController.php
$post->addMedia($image)->manipulations(['or' => '90'])->toMediaLibrary('images');

But the manipulation doesn't work. Any clue of what I am doing wrong? Is the Glide Api supported only for media conversions?

setManipulations Watermark path

I am trying to add a watermark to my image:

$this->addMediaConversion('large')
    ->setManipulations(['fm' => 'jpg', 'mark' => 'watermark.png', 'markw' => '40', 'markh' => '40', 'markpad' => '15', 'markpos' => 'top-left'])
    ->performOnCollections('images');

Following the Glide doc (http://glide.thephpleague.com/1.0/api/watermarks/) I added a new filesystem for watermarks, in the laravel's config/filesystems.php file.

However, my generated thumb doesnt have any watermark on it. And there is no log error report.

Where should I place my watermark.png file ? I tried in storage/images and storage/watermarks and even modifying 'mark' => storage_path('images/watermark.png') but I can't get it working.

Signature is not valid

Laravel 5.1.7

League \ Glide \ Http \ SignatureException
Signature is not valid.

Can't make it work :'( But it works well without secure URL.

laravel-glide published and hasn't been changed (using default). Image new.jpg placed in folder ./storage/images and folder is writable.
./storage/glide/cache is writable too. Temporary files directory is writable.

In template I'm just trying to call:

<img src="{{ GlideImage::load('new.jpg') }}">

What could it be?

Non-secure urls (no signatures) option

Hello!

First of all thank you for the project, nice one!

Could you advise please, I'm trying to use it with URLs generated from the Angular front-end, dynamically, so not using GlideImage::load, but something like .../img/image.jpg?w=200 with image urls coming from a model. The problem is in that case I don't have a signature parameter and can't pass the
SignatureFactory::create($this->app['config']->get('app.key'))->validateRequest($request); validator. So was thinking, maybe the signature should be optional? I believe in Glide they say it's an "additional security feature", I totally understand the purpose, but don't see an easy solution in my case. Do you have any suggestions or workarounds?

Thank you!

getURL and Load in v3

Hi,

In v2 I did things like:

return GlideImage::load($this->avatar, 
         ['w' => 100, 'h' => 100, 'fit' => 'crop'])->getURL();

But I wanna upgrade to v3, but how to achieve the same? I found out that I had to add the storage_path to the load, but the getURL returns Fatal error: Call to undefined method Spatie\Glide\GlideImage::getURL()

return GlideImage::create(storage_path('app/images/'.$this->avatar), 
     ['w' => 100, 'h' => 100, 'fit' => 'crop'])->getURL();

As far I could see it wasn't possible to use load() anymore, but the docs still shows it:
https://www.dropbox.com/s/3vbc6d1fd8lch2n/Schermafdruk%202016-02-12%2020.25.12.png?dl=0

S3 support

Hello again! You've mentioned in a readme, that were planning at some point to add other disk drivers support, would +1 an S3 please. We have common "file uploads" going to/serving from s3, but images that require Glide cropping and so on are still on local disk, ideally would like to move all the uploads to Amazon. Not sure though about the best practices regarding cache for example. Have seen a few stackoverflow questions/discussions on having originals on s3, cache on local or disabling cache completely and just serving from s3...

Call to undefined method GlideImage::create()

Immediatly after install I get the following error when testing in my routes.

FatalErrorException in Facade.php line 218:
Call to undefined method Spatie\Glide\GlideImage::create()

I followed the installation instructions, any idea what I might be doing wrong?

Target [League\Flysystem\FilesystemInterface] is not instantiable

I follow all install instructions that you saied. and I write a custom Route to show images :

Route::get('/showImage/{w}/{h}/{src}', function (League\Glide\Server $server, Illuminate\Http\Request $request) { $server->outputImage($request); })->where('src', '.+');

but when run the Route bellow error is shown :
BindingResolutionException in Container.php line 745: Target [League\Flysystem\FilesystemInterface] is not instantiable.

Incorrectly assumes the namespace is always "App"

From /Spatie/Glide/Controller/GlideImageController.php

use App\Http\Controllers\Controller;

This assumes that the application namespace is "App", which won't always be the case. When the app namespace has been changed from the default, it causes a fatal error: Class 'App\Http\Controllers\Controller' not found. I can change it manually, but every time the package is updated, it's going to revert.

Is there anything that can be done about this? Could this be helpful?

https://github.com/laravel/framework/blob/5.0/src/Illuminate/Console/AppNamespaceDetectorTrait.php

The image is not resizing

So I followed all the steps and the image is loaded but with original dimensions.

All my images are in the public folder and from what I can see using a debugger in the GlideServiceProvider, the router is not working. Maybe because my images are not in the storage folder?

Appending GlideImage::load as Attribute to Model

I wanna append an attribute to my Photo Model with a full URL including signature and the dimensions.

Normally I'm doing it in the view, and it works:

<img src="{{ GlideImage::load($photo->path, ['w' => 100, 'h' => 100, 'fit' => 'crop']) }}">

But I want it in my JSON-response for Angular-reasons. So I did this in my Model:

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

use GlideImage;

class Photo extends Model
{
    protected $fillable = ['foobar', 'path'];
    protected $appends = ['thumb'];

    public function getThumbAttribute()
    {
        return GlideImage::load($this->path, ['w' => 241, 'h' => 187, 'fit' => 'crop']);
    }
}

But that returns just an empty:
schermafdruk 2015-11-18 15 56 37
What I expected was an URL like: /img/photos/f02cd882f546a30cb435b22c1e337f7b.jpg?w=100&amp;h=100&amp;fit=crop&amp;s=f9b52d8c713ac525da0d6accff50822e

Glide composer dependency broken

The version for the thephpleague/glide dependency is listed as 0.3.*.

The 0.3-dev tag fulfils this requirement but the directory structure of the phpleague library has been changed in this version resulting in this error:

Class 'League\Glide\Api\Manipulator\Orientation' not found in /home/vagrant/Sites/creuset/vendor/spatie/laravel-glide/src/Spatie/Glide/GlideApiFactory.php on line 29

3.0 depends on php 7. Really needed?

Hello, it's a very strict requirement that it needs php 7. My host doesnt support it. The original package of league/glide doesn't need php7 for league/glide 1.0.0. And i wanna use the 1.0.0 leage's glide because of the new features they added.

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.