Giter Site home page Giter Site logo

folkloreinc / laravel-image-legacy Goto Github PK

View Code? Open in Web Editor NEW
272.0 16.0 80.0 5.05 MB

Image manipulation library for Laravel 4 and 5 based on Imagine (https://github.com/avalanche123/Imagine) and inspired by Croppa for easy url based manipulation (with caching)

PHP 94.84% JavaScript 2.59% Shell 2.57%
image-manipulation php imagine laravel manipulate-images crop

laravel-image-legacy's Introduction

Laravel Image

Laravel Image is an image manipulation package for Laravel 4 and 5 based on the PHP Imagine library. It is inspired by Croppa as it can use specially formatted urls to do the manipulations. It supports basic image manipulations such as resize, crop, rotation and flip. It also supports effects such as negative, grayscale, gamma, colorize and blur. You can also define custom filters for greater flexibility.

Latest Stable Version Build Status Total Downloads

The main difference between this package and other image manipulation libraries is that you can use parameters directly in the url to manipulate the image. A manipulated version of the image is then saved in the same path as the original image, creating a static version of the file and bypassing PHP for all future requests.

For example, if you have an image at this URL:

/uploads/photo.jpg

To create a 300x300 version of this image in black and white, you use the URL:

/uploads/photo-image(300x300-crop-grayscale).jpg

To help you generate the URL to an image, you can use the Image::url() method

Image::url('/uploads/photo.jpg',300,300,array('crop','grayscale'));

or

<img src="<?=Image::url('/uploads/photo.jpg',300,300,array('crop','grayscale'))?>" />

Alternatively, you can programmatically manipulate images using the Image::make() method. It supports all the same options as the Image::url() method.

Image::make('/uploads/photo.jpg',array(
	'width' => 300,
	'height' => 300,
	'grayscale' => true
))->save('/path/to/the/thumbnail.jpg');

or use directly the Imagine library

$thumbnail = Image::open('/uploads/photo.jpg')
			->thumbnail(new Imagine\Image\Box(300,300));

$thumbnail->effects()->grayscale();
	
$thumbnail->save('/path/to/the/thumbnail.jpg');

Features

This package use Imagine for image manipulation. Imagine is compatible with GD2, Imagick, Gmagick and supports a lot of features.

This package also provides some common filters ready to use (more on this):

  • Resize
  • Crop (with position)
  • Rotation
  • Black and white
  • Invert
  • Gamma
  • Blur
  • Colorization
  • Interlace

Version Compatibility

Laravel Image
4.2.x 0.1.x
5.0.x 0.2.x
5.1.x 0.3.x
5.2.x 0.3.x

Installation

Dependencies:

Server Requirements:

Installation:

1- Require the package via Composer in your composer.json.

{
	"require": {
		"folklore/image": "0.3.*"
	}
}

2- Run Composer to install or update the new requirement.

$ composer install

or

$ composer update

3- Add the service provider to your app/config/app.php file

'Folklore\Image\ImageServiceProvider',

4- Add the facade to your app/config/app.php file

'Image' => 'Folklore\Image\Facades\Image',

5- Publish the configuration file and public files

$ php artisan vendor:publish --provider="Folklore\Image\ImageServiceProvider"

6- Review the configuration file

app/config/image.php

Documentation

Roadmap

Here are some features we would like to add in the future. Feel free to collaborate and improve this library.

  • More built-in filters such as Brightness and Contrast
  • More configuration when serving images
  • Artisan command to manipulate images
  • Support for batch operations on multiple files

laravel-image-legacy's People

Contributors

91abdullah avatar dmongeau avatar kryptonit3 avatar mauserrifle avatar tacone avatar tontonsb 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-image-legacy's Issues

Limit only the specified type and size

I have now made several appeals:

http://localhost/uploads/11-image(_x501).jpg
http://localhost/uploads/11-image(_x601).jpg
http://localhost/uploads/11-image(_x700).jpg
http://localhost/uploads/11-image(200x300-crop).jpg

And each time create a miniature disk of the desired size. That's cool, but I risk filling the disk. I only need:

http://localhost/uploads/11-image(_x90).jpg
http://localhost/uploads/11-image(200x300-crop).jpg

All the rest you dismiss. How to do it?

Image file missing

I tried to use this libary but always return with the following error.

FileMissingException in ImageManager.php line 151:
Image file missing`

I know, I need to use with try / catch, BUT when I using the laravel built in $pic = Storage::get($file->path) and return it in a response with an image content-type header and the important infos, its works fine, and i got back the picture.

After I use $pic = Image::make($file->path); and the error is occurred.

There is any chance to use the variable returned by Storage?

Thumbor?

I think you should take a look at and contribute to https://github.com/globocom/thumbor/wiki It's a proven and trusted solution, with Laravel4 wrapper, that does everything you're planning to do and more. Not to discourage you, but in this case I personally think you're reinventing the wheel.

Good luck!

Write images to configurable directory instead the same as original image

Hi,

suppose I have custom filter called 'product_view' with size 120x120 and my original images was uploaded to public/uploads/photos.

When I set write option to true, then the package writes generated thumbnail into the same directory as original, so when my filter settings has been changed for example to size 110x110 then generated thumbnail is no longer valid, cause it exists but with 120x120 size, so I have to remove it for regenerate with the next request.

When the write image path will be configurable then I can set it to i.e. public/uploads/thumbs and then clean this directory for the regeneration.

Or it may be other possible solution for this problem?

How to use this lib on Laravel 5.5.24

Hi how to use this library with Laravel 5.5 ?

$> composer require folklore/image

gives me the following output

Using version ^0.3.20 for folklore/image
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - Installation request for folklore/image ^0.3.20 -> satisfiable by folklore/image[v0.3.20].
    - Conclusion: remove laravel/framework v5.5.24
    - Conclusion: don't install laravel/framework v5.5.24
    - folklore/image v0.3.20 requires illuminate/support 5.1.*|5.2.*|5.3.*|5.4.* -> satisfiable by illuminate/support[v5.1.1, v5.1.13, v5.1.16, v5.1.2, v5.1.20, v5.1.22, v5.1.25, v5.1.28, v5.1.30, v5.1.31, v5.1.41, v5.1.6, v5.1.8, v5.2.0, v5.2.19, v5.2.21, v5.2.24, v5.2.25, v5.2.26, v5.2.27, v5.2.28, v5.2.31, v5.2.32, v5.2.37, v5.2.43, v5.2.45, v5.2.6, v5.2.7, v5.3.0, v5.3.16, v5.3.23, v5.3.4, v5.4.0, v5.4.13, v5.4.17, v5.4.19, v5.4.27, v5.4.36, v5.4.9].
    - don't install illuminate/support v5.1.1|don't install laravel/framework v5.5.24
    - don't install illuminate/support v5.1.13|don't install laravel/framework v5.5.24
    - don't install illuminate/support v5.1.16|don't install laravel/framework v5.5.24
    - don't install illuminate/support v5.1.2|don't install laravel/framework v5.5.24
    - don't install illuminate/support v5.1.20|don't install laravel/framework v5.5.24
    - don't install illuminate/support v5.1.22|don't install laravel/framework v5.5.24
    - don't install illuminate/support v5.1.25|don't install laravel/framework v5.5.24
    - don't install illuminate/support v5.1.28|don't install laravel/framework v5.5.24
    - don't install illuminate/support v5.1.30|don't install laravel/framework v5.5.24
    - don't install illuminate/support v5.1.31|don't install laravel/framework v5.5.24
    - don't install illuminate/support v5.1.41|don't install laravel/framework v5.5.24
    - don't install illuminate/support v5.1.6|don't install laravel/framework v5.5.24
    - don't install illuminate/support v5.1.8|don't install laravel/framework v5.5.24
    - don't install illuminate/support v5.2.0|don't install laravel/framework v5.5.24
    - don't install illuminate/support v5.2.19|don't install laravel/framework v5.5.24
    - don't install illuminate/support v5.2.21|don't install laravel/framework v5.5.24
    - don't install illuminate/support v5.2.24|don't install laravel/framework v5.5.24
    - don't install illuminate/support v5.2.25|don't install laravel/framework v5.5.24
    - don't install illuminate/support v5.2.26|don't install laravel/framework v5.5.24
    - don't install illuminate/support v5.2.27|don't install laravel/framework v5.5.24
    - don't install illuminate/support v5.2.28|don't install laravel/framework v5.5.24
    - don't install illuminate/support v5.2.31|don't install laravel/framework v5.5.24
    - don't install illuminate/support v5.2.32|don't install laravel/framework v5.5.24
    - don't install illuminate/support v5.2.37|don't install laravel/framework v5.5.24
    - don't install illuminate/support v5.2.43|don't install laravel/framework v5.5.24
    - don't install illuminate/support v5.2.45|don't install laravel/framework v5.5.24
    - don't install illuminate/support v5.2.6|don't install laravel/framework v5.5.24
    - don't install illuminate/support v5.2.7|don't install laravel/framework v5.5.24
    - don't install illuminate/support v5.3.0|don't install laravel/framework v5.5.24
    - don't install illuminate/support v5.3.16|don't install laravel/framework v5.5.24
    - don't install illuminate/support v5.3.23|don't install laravel/framework v5.5.24
    - don't install illuminate/support v5.3.4|don't install laravel/framework v5.5.24
    - don't install illuminate/support v5.4.0|don't install laravel/framework v5.5.24
    - don't install illuminate/support v5.4.13|don't install laravel/framework v5.5.24
    - don't install illuminate/support v5.4.17|don't install laravel/framework v5.5.24
    - don't install illuminate/support v5.4.19|don't install laravel/framework v5.5.24
    - don't install illuminate/support v5.4.27|don't install laravel/framework v5.5.24
    - don't install illuminate/support v5.4.36|don't install laravel/framework v5.5.24
    - don't install illuminate/support v5.4.9|don't install laravel/framework v5.5.24
    - Installation request for laravel/framework (locked at v5.5.24, required as 5.5.*) -> satisfiable by laravel/framework[v5.5.24].


Installation failed, reverting ./composer.json to its original content.

Laravel 6

Hi, just wondering if you plan to extend this plugin, to be compatible with Laravel 6 ?

Thanks in advance,

max_crops ?

Bonjour,

Have you a security system like "max_crops" in cropa ? It's important for disk space on the server.

Served images dont open

When trying to open an edited image by url the image dont show and returns error 404 not found.

But images created from code work without problem and are stored in the same folder as the ones that must be served. It works under my development environment with apache but it doesnt in production with nginx.

I cant seem to find the problem.

Any help would be appreciated.

Fix for laravel 5.2

fix please laravel 5.2

Class: Folklore\Image\ImageController;

replace line: use Illuminate\Foundation\Bus\DispatchesCommand;
on: use Illuminate\Foundation\Bus\DispatchesJobs;

and load trait
replace line: use DispatchesCommand, ValidatesRequests;
on: use DispatchesJobs, ValidatesRequests;

thanx

Laravel 5.0 compatibility

Hi, just wondering if you plan to extend this plugin, to be compatible with L5 ?

Thanks in advance,

Change format with url call

As far as I understood, I can load an image and save it in different format programmatically.

Could we also add this functionality to the url API?

The syntax could be catpic.jpg-image(200,200).png - meaning that if everything before -image is a real path to existing file then treat the final extension as the new format.

Route cache generation not possible due Closure

The following code should just use a Controller:

$app->make('router')->get('{path}', function($path) use ($app)

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

php artisan route:cache
Route cache cleared!



  [LogicException]                                                   
  Unable to prepare route [{path}] for serialization. Uses Closure.  

Enable image browser caching

Image route returning next headers:
expires:-1 pragma:no-cache

It's wrong, browser should cache images.
How it can be fixed?

Downscale only option?

I would like to resize the image only if it is larger than the size limits. This is my current code:

$fopen = Image::make($image, [
	'width' => 2400,
	'height' => 1600
])->get($ext);

Unfourtunately it upscales every image that is smaller in both dimensions. Can I pass some option or do something else to disallow upscaling?

I think I did this successfully before and I believe this was changed in version 0.1.6.

Images uploaded with an iphone can be upside down.

I have found that images uploaded from an iphone or just taken from an iphone would be in an incorrect rotation. This is because of the iphone rotating its photos by modifying the exif information and not actually the photo.

So the question would be how to turn or rotate the image to the correct rotation by reading the exif information?

Thanks by the way

Saving Image Doesn't Work

I would like to save image in a directory from public folder in laravel 5.6. So, I used the code as documentation did like below.

$orginal_path = $request->file->store( 'cropped', 'public' );

$medium = Image::make($orginal_path,array(
	'width' => 300,
	'height' => 300,
	'grayscale' => true
))->save($orginal_path);	

I added true for image.php from config directory.

'write_image' => true,

Did I miss anything?

Laravel 5.7

Please change dependencies on laravel 5.7.*

Support for custom image saving path

Is-it possible to save the generated images to a different folder than the one the images are in, example :
from "/my/upload/image/cache.jpg"
to "/cache/my/upload/image/cache.jpg"

Registering custom filters - Laravel 5

The documentation on custom filters recommends registering filters in the app/start/global.php file.
As of the current version of Laravel this file no longer exists. I've tried defining a filter as middleware but this did not work. Anyone have an idea of the best place to register these filters now we don't have a global.php file?

image resize regeneration problem

I am using Image::url('uploads/imagename',400, 400), image exists but it is not regerating the image and throwing 404 error. I am using nginx server.
eg. http://server_url/uploads/imagename-image(400x400).jpg

Support for AWS S3

Hi,

Is possible to add compatibility with AWS S3? Or CloudFront maybe?

I have all the images in S3 and woud like to use some library like this or Croppa

Image inside white container [HELP]

Im trying to insert an image uploaded by a user with unknown sizes inside a container with a known size
For example, the container must be 960px X 540px and the image uploaded by a user is 700X500.
I want the uploaded image to be in the center of the container.

Any help would be apreciated.

Potrait images from iphone got rotated 45 degrees

Hi,

I experience an issue with mobile phones. When I upload an image to my server and then run the image crop from a portrait image it gets cropped and rotated 45 degrees anti-clockwise. This only occurs when the image is taken using an iPhone.

On android devices it works as expected.

Does anyone have a clue of what can be happening?

The code I use to make the crop is as follows:
Image::url($user->image,200,200,array('crop'))

$user->image is the route to the original image file that is uploaded exactly as it was taken, portrait.

Road to v1

The development of version 1.0 is currently in ongoing in the branch v1.

Here are the new features:

Sources
The main difference between v1 and prior versions is the support of multiple sources. It make it easy to pull images from a laravel filesystem, or local filesystem or any remote url. You can take a look at the configuration file for a better idea: https://github.com/Folkloreatelier/laravel-image/blob/v1/src/config/image.php.

Basically, you will be able to use the facade on any source, for example:

$image = Image::source('cloud')->make('image-on-cloud.jpg', [
    'width' => 100,
    'height' => 100
]);

Image::source('cloud')->save($image, 'image-on-cloud-thumbnail.jpg');

Filters
Filters has been moved to classes and are now declared in the configuration file. It still support closure and array of other filters.

Routes
You can define multiple routes with lots of options. Here is an example of the configuration for the default route:

    'routes' => [
        'default' => [
            // The path of the route. {pattern} will be replaced by the url pattern
            // for this route according to the url format.
            'route' => '{pattern}',
            
            // A domain that will be used by the route
            'domain' => null,
            
            // Any middleware you want ot add on the route.
            'middleware' => [],
            
            // The name of the source to get the image. If it is set to null,
            // it will get use the default source.
            'source' => null,
            
            // Allow to specify a size as filter
            'allow_size' => true,
            
            // Allow to specify filters in url. You can also set this to
            // an array of specific filters to restrict this route to those filters.
            // Example: ["negative"]
            'allow_filters' => true,
            
            // Disallow some filters. Can be set to an array of filters.
            'disallow_filters' => false,
            
            // Any url options you want to override.
            'url' => [],
            
            // You can specify base filters that will be applied to any image
            // on this route.
            'filters' => [
                'width' => 100
            ],
            
            // Expires header in seconds
            'expires' => 3600 * 24 * 31,
            
            // Any headers you want to add on the image
            'headers' => [],
            
            // Cache the file on local machine
            'cache' => true,
            
            // The path where the images are stored. It is defined to public path,
            // so the files would be statically served on next request.
            'cache_path' => public_path()
        ]
    ]

URL
The generation of URL is easier and more configurable. You can define a general format that will apply to each routes or override it on each route.

Here is the general config:

    'url' => [
        // The format of the url that will be generated. The {filters} placeholder
        // will be replace by the filters according to the filters_format.
        'format' => '{dirname}/{basename}{filters}.{extension}',
        
        // The format of the filters that will replace {filters} in the
        // url format below. The {filter} placeholder will be replace by
        // each filter according to the filter_format and joined
        // by the filter_separator.
        'filters_format' => '-image({filter})',
        
        // The format of a filter.
        'filter_format' => '{key}({value})',
        
        // The separator for each filter
        'filter_separator' => '-'
    ],

These are the remaining steps before release:

  • Add a source based on url
  • Javascript helper
  • Unit tests
  • Documentation

Quality of scaled image

Hello,

I have tried to scale down some images with your package and it works. But I'm wondering about the quality of the resized ones...they seem to a little blurred. Is this normal or do you have an idea where this can come from? Maybe I have done something wrong.

Greetings,

ZengineAlex

Auto compute height

Hi,

is there a way to autocompute the height? i will just give the width that i want to crop and the height will auto compute base on the width.

Example : Image width = 1000, height = 500
and i want to crop the image by giving the width size only,
width = 500, then the height will be 250, depend on how many percent the width will less that was also implement to height.

Write permission checking in ImageServe.php

I apologize in advance if I didn't understand the intended usage correctly.

Suppose I serve the file images/placeholder.png and want to write the resized file to the same directory. I have set 'write_image' => true, in config and all I get is an exception that the destination is not writable.

I looked into the source and it seems that the block in lines 45-61 is to be blamed:

    if ($this->config['write_image']) {
        // make sure the path is relative to the document root
        if (strpos($realPath, public_path()) === 0) {
            $imagePath = substr($realPath, strlen(public_path()));
        }
        $destinationFolder = $writePath ?: dirname($imagePath);
        $destinationFolder = public_path(trim($writePath, '/') . '/' . ltrim(dirname($imagePath), '/'));
        
        if (isset($writePath)) {
            \File::makeDirectory($destinationFolder, 0770, true, true);
        }

        // Make sure destination is writeable
        if (!is_writable(dirname($destinationFolder))) {
            throw new Exception('Destination is not writeable');
        }
    }

The main offending check is is_writable(dirname($destinationFolder)). This actually checks if the parent folder of the images directory is writable. In my case I would like image to be written in /var/www/myProject/public/images, but this check tests if /var/www/myProject/public is writable. It is not writable and it shouldn't be and I get thrown an exception. But the actual $destinationFolder was writable all the time.

Also line 51 ($destinationFolder = $writePath ?: dirname($imagePath);) seems to do nothing and instantly get overwritten by the next line.

Option to scale only the images width

Hi there,
I have a small feature suggestion / idea.

If you'd like an image to be only scaled to a specific width and don't care for the height, you currently have to use an URL like:

image02-image(175x9999).jpg

Instead I'd be really neat to use something like one of this: image02-image(175x*).jpg or image02-image(175x0).jpg or image02-image(width-175).jpg or something similar.

What do you think of this?

Image::url returning url but image is not resized

I'm trying to use this on Laravel 4.2, I have installed Imagine too and followed all steps (config publish, inclusive) with no error. When I call Image::url to make a resize of an image, this returns the url but the new image is not generated on the path.

Image::url($content->original_file_url,300,300)

If this line return the new url, the package is working in part, why the new image is not being generated?

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.