intervention / image Goto Github PK
View Code? Open in Web Editor NEWPHP Image Processing
Home Page: https://image.intervention.io
License: MIT License
PHP Image Processing
Home Page: https://image.intervention.io
License: MIT License
Quick question before i use this package:
Does it overwrite an image if it already exists?
Im looking for a nice quick way to upload images and i need a specific filename for it so i would like to overwrite images if they already exist. Or can i delete/replace images?
And does it allow me to save to a new directory (which needs to be created first)?
Is it possible to build a function to optimize the image for web? I think it can really reduce the file size. Think of something like http://www.smushit.com/ysmush.it/
Hello.
I'm using the resize canvas to obtain exact sizes witch i want.
$imgs->resizeCanvas(160,122, 'center',false,'ffffff');
I want to know if is possible instead of white background to have transparent?
image is png.
Hi,
Thank you for producing this library - It is amazingly useful!
I was wondering what the possibility may be of having some sort of blur function included in this library? I'm new to image processing with PHP (which is why I love your library so much) and I don't really know where I would look to get such functionality.
Thanks for your time
Is there a way to trim whitespace similar to photoshop?
Hello. I want to protect phonenumbers by generating an image instead using string. I don't want to save the image, just display directly into a tag. I have an standar white background image wich i load with make.
My code in blade
img src="{{ListController::GeneratePhoneNumberImage($phonenumbe)}}"
My function
public static function GeneratePhoneNumberImage($phonenumber)
{
$img = Image::make('img/bk_phone.png');
$img->text($phonenumber);
$img->text('foo', 0, 0, 72, array(255, 255, 255, 50));
return $img;
}
I tried also to set header before return but didn't worked.
Into inspector it display just a bunch of characters to the src attribute.
Thanks.
Hello guys, thank you for this amazing library. I am using its integration with Laravel 4 and it works wonderfully.
I encountered an error when trying to save an image to a directory that did not exist. It is not a permission problem, it is just a feature that is missing: create the directory first if it does not exists. Maybe its an easy fix, but I don't feel comfortable enough to modify the library myself...
Hope you guys can take a look into it for a future release.
Thank you!
Current documentation is really good, thank you!
But when I see some methods I wish result will be more obvious.
What about images "before" and "after" for some cases?
I have done few experiments with this idea in my repo
I am satisfied with result, but I don't find direct way to contribute documentation, so created this issue...
Opinions?
Is it planned to support interlacing on your image library?
Hey,
This looks great but your wording is going to scare of non-Laravel users, which is bad for uptake of this library.
Instead you should call it a generic library, which has optional Laravel 4 support.
It's a great library, don't play it short by making it look framework specific when it doesn't need to be!
Nice library :)
Is see you have a cache option, but is it also possible to cache an image to an file? Similar to https://github.com/Gregwar/Image#using-cache
So you could do <img src="<?php echo Image::make('public/image.jpg')->resize(150, 150)->url(); ?>" />
on the original, and create or retrieve a cached version, based on the operations/options.
I am using your class to load images from different sources and formats, convert them to jpeg and save them to the server hdd.
Is there a built in possibilty to change the background color of the resulting jpeg? when converting some transparent PNGs, the background color of the jpeg changes to black.
Hi sir. Im integrating it in laravel 4. i follow your instuctions but still got this error. Im also stuck in this, i believe this is a useful package, ill be thankful for any help.
https://github.com/Intervention/image/blob/master/src/Intervention/Image/Image.php#L1742
Function getimagesize returns type 4, if the image in PNG format.
As far as I saw I didn't find on documentation a function where we can specify the color like IMG_FILTER_COLORIZE
does. Any idea or is this not implemented yet?
See examples here
Hello. when i am loading and image from a certain address,
eg:
$img = Image::make('/uploads/a/myimage.jpg');
i receive this error:
{"error":{"type":"Intervention\Image\Exception\ImageNotFoundException","message":"Image file (/uploads/a/myimage.jpg) not found","file":"C:\xampp\htdocs\bubamaro.dev\vendor\intervention\image\src\Intervention\Image\Image.php","line":192}}
Seems that it changes the image address by putting \ in front of /
I am working local using xampp.
What should i do?
Thank you.
Hi there!
After the new releaser, i just update the package by composer, and now the ->text got all text in black (font and background) as the font didn't rendered the text - get all text as black boxes.
It's a bug, something new that i'm missing or what?!
Tks in advance.
Hi, I just installed this by composer. After installing I added providers and aliases. It does not work. But if I use "use Intervention\Image\Image;" before code; it's works. I want to work intregrated to Laravel. For any method I get the error: "Call to undefined method Intervention\Image\Facades\Image::open()". What's happening? o:
Thanks, it looks like a great package images.
It would be great if the images exif data could be customised, this is useful for adding more discrete watermarks or other meta data.
Is there any way to use this to make animated gifs? Such as combining the frames of images.
Trying to use this lib but I get the following after composer.phar update
FatalErrorException: Error: Call to undefined method Intervention\Image\Image::all()
regareds // Johannes
Hi.
I'm using your beautiful class with Laravel 4. I've an issue when I try to resize and save the Image the Image class return to me an error "imagefile(path)notfound" but actually the path is correct, the folder has permissions set to 0775. I can't understand what's wrong.
$files = Input::file('files');
foreach ($files as $file)
{
$mime = $file->getMimeType();
$ext = $file->guessExtension();
$size = getimagesize($file);
$newName = str_random(5).'_'.str_random(4).'_'.str_random(3);
$newPath = $path.'/'.$newName;
$photoName = $newName.'.'.$ext;
try {
File::makeDirectory(Url::asset($newPath));
$file->move($newPath, $photoName); // Original file
Image::make(Url::asset($newPath.'/'.$photoName))->widen(160)->save(Url::asset($newPath.'/'.$newName.'_thumb.'.$ext)); // Thumbnail
}
catch(Exception $e)
{
return Response::json($e->getMessage(), 400);
}
Maybe nice to implement a tool for image optimization? Like jpegoptim and optipng.
See http://jamiemason.github.io/ImageOptim-CLI/
I just installed and configured this into my Laravel 4 installation, and I got this error.
{"error":{"type":"Symfony\Component\Debug\Exception\FatalErrorException","message":"Call to undefined method Intervention\Image\Facades\Image::newQuery()","file":"/home/projectx/public_html/bootstrap/compiled.php","line":5464}}
I have run composer dump-autoload.
Probably a simple mistake on my part, so I apologize to bother you with this...
This is from my terminal. I am running ubuntu
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 intervention/image dev-master -> satisfiable by intervention/image[dev-master].
- intervention/image dev-master requires ext-gd * -> the requested PHP extension gd is missing from your system.
I went through the issues, but did not find anything like this.
I followed the instructions as per the documentations.
"require": {
"laravel/framework": "4.0.*",
"way/generators": "dev-master",
"intervention/image": "dev-master"
},
and
"minimum-stability": "dev"
Still, doesnt work.
I am new in installing packages with laravel. Pls help me out!
Hi,
If I want to resize an image like 800x800, then 400x400 then 200x200. Should I make each time a call to Image::make() or is there a way to "reset" and be sure to always work with the original and not cutting the 400x400 from the 800x800 ans the 200x200 from the 400x400 ? Also it will save some memory.
Also is there a way to prevent from resizing if the image is smaller than the asked size ?
Thanks
I am using this package with laravel and for some files that I am trying to resize it happens randomly I get this error:
imagecreatefromjpeg(): gd-jpeg, libjpeg: recoverable error: Premature end of JPEG file"
Stack Frame
/Applications/MAMP/htdocs/laravelweb/vendor/intervention/image/src/Intervention/Image/Image.php
case IMG_PNG:
case 3:
$this->resource = imagecreatefrompng($path);
break;
case IMG_JPG:
case 2:
$this->resource = imagecreatefromjpeg($path);
break;
Hi,
I've tried inserting a transparent watermark using a png but the transparent section of the watermark is rendered as white. I've attached a copy of the image it generates along with the watermark I am using.
Do you know if transparent watermark overlays are possible with the current script, or if I am doing this wrong? The code I used was using the example provided in the docs.
Thanks
Installation steps:
c:\xampp\htdocs\laravel>php composer.json "intervention/image": "dev-master"
{
"require": {
"laravel/framework": "4.0.",
"zizaco/confide": "dev-master",
"zizaco/entrust": "dev-master",
"laravelbook/laravel4-powerpack": "dev-master",
"jasonlewis/basset": "",
"jasonlewis/expressive-date": "1.*",
"bigelephant/presenter": "dev-master"
},
"autoload": {
"classmap": [
"app/commands",
"app/controllers",
"app/models",
"app/presenters",
"app/database/migrations",
"app/tests/TestCase.php"
]
},
"minimum-stability": "dev"
}
c:\xampp\htdocs\laravel>composer update
Loading composer repositories with package information
Updating dependencies (including require-dev)
Writing lock file
Generating autoload files
And then I get error when launching localhost/laravel/public
Error:
FatalErrorException: Error: Class 'Intervention\Image\ImageServiceProvider' not found in C:\xampp\htdocs\laravel\vendor\laravel\framework\src\Illuminate\Foundation\ProviderRepository.php line 123
When resizing transparent GIFs, the background becomes black. I have managed to fix it by making the following update in the modify() function:
private function modify($dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h)
{
// create new image
$image = imagecreatetruecolor($dst_w, $dst_h);
// preserve transparency
$transIndex = imagecolortransparent($this->resource);
if ($transIndex != -1) {
$rgba = imagecolorsforindex($image, $transIndex);
$transColor = imagecolorallocate($image, $rgba['red'], $rgba['green'], $rgba['blue']);
imagefill($image, 0, 0, $transColor);
imagecolortransparent($image, $transColor);
}
else {
imagealphablending($image, false);
imagesavealpha($image, true);
}
// copy content from resource
imagecopyresampled(
$image,
$this->resource,
$dst_x,
$dst_y,
$src_x,
$src_y,
$dst_w,
$dst_h,
$src_w,
$src_h
);
// set new content as recource
$this->resource = $image;
// set new dimensions
$this->width = $dst_w;
$this->height = $dst_h;
return $this;
}
Hello.
I'm using this awesome class with Laravel 4 but I cannot understand where I've to put my file .ttf
I tried to put it inside the /public directory of laravel 4 and call it with URL::asset() but nothing.
I tried to put it inside the controller (This is mad i know) still nothing
Finally I even tried to put it inside /vendor/intervention folder but nothing
I Don't know where can I put it
I suggest you to add a best_fit method like https://github.com/claviska/SimpleImage/blob/master/src/abeautifulsite/SimpleImage.php#L520
I find that very useful.
Hi,
Maybe I'm missing something, It does work with a normal path, but when using the Input::file('image') as follows;
Image::make(Input::file('image'))->resize(300,200)->save('public/foo.jpg');
I get an
ErrorException: Notice: Undefined index: extension in .../vendor/intervention/image/src/Intervention/Image/Image.php line 190
I got back in your package and found you're using pathinfo($path); to get the extension. After trying pathinfo(Input::file('image')); I get the following:
array(3) {
["dirname"]=>
string(26) "/Applications/MAMP/tmp/php"
["basename"]=>
string(9) "phpC4MWdR"
["filename"]=>
string(9) "phpC4MWdR"
}
var_dump-ing Input::file('image'); gives me:
object(Symfony\Component\HttpFoundation\File\UploadedFile)#9 (7) {
["test":"Symfony\Component\HttpFoundation\File\UploadedFile":private]=>
bool(false)
["originalName":"Symfony\Component\HttpFoundation\File\UploadedFile":private]=>
string(8) "33_b.jpg"
["mimeType":"Symfony\Component\HttpFoundation\File\UploadedFile":private]=>
string(10) "image/jpeg"
["size":"Symfony\Component\HttpFoundation\File\UploadedFile":private]=>
int(210223)
["error":"Symfony\Component\HttpFoundation\File\UploadedFile":private]=>
int(0)
["pathName":"SplFileInfo":private]=>
string(36) "/Applications/MAMP/tmp/php/phpC4MWdR"
["fileName":"SplFileInfo":private]=>
string(9) "phpC4MWdR"
}
I have a problem when I upload a gif file. The gif doesn't work anymore, there is no movement.
I work with laravel 4, my code:
Image::make($file->getRealPath())->resize(238, null, true)->save('img/photos/' . $fileName, 100);
Uploading goes well, everything works fine except the gif files. Do I something wrong or is it a bug?
I try to resize a photo's width to 1000 or height to 1000 but it's unsuccessful.
I tried to put php memory limit to 256MB. Still can't resize... I can resize image smaller than 500 only.
Anyone know how to solve it ? Really appreciated.
Looks like whatever was originally done in #1 has come back - I've just installed the latest version through Composer in to my Laravel 4 project, aliased under ImageManager (I already have Image).
// Input is a 600x300 image, should be resized to 150x75
$file = \ImageManager::make( \Input::file('file')->getRealPath() );
$file->resize(150, 150, true)->save('foo.jpg');
As I understand it, specifying true
on the ratio parameter should make it treat the width and height as max-width and max-height, while maintaining the ratio of the input file. Am I misunderstanding this (and if so, how do I achieve what I'm aiming for) or is anyone else able to replicate this?
Cheers :)
Following the Laravel 4 integration and i got this error. I confirmed i have gd library compiled with php.
Any ideas?
Please add support for SVG files.
Thanks!
Is it perhaps possible to extend the resize function so it'll preserve the ratio and treat the width and heigh values as maximum values?
In the following example public/foo.jpg
is 300x600.
$img = Image::make('public/foo.jpg');
$img->resize(600, 300, true);
$img->save('public/bar.jpg');
Because the true
flag was passed the image's ratio will be preserved and will be resized to 150x300 because 300 is the maximum height.
Can something like this be implemented?
Great library btw. Thanks a lot for it!
Hi,
Create a function that return true if the file was successfully saved and false otherwise. it could be use like this:
Image::make(Input::file('photo')->getRealPath())->resize(300, 200)->save('foo.jpg')->hasSaved();
Imagine is the most robust image-intervention package there is out there, and it supports all drivers (GD, Imagick etc).
This would add a lot of features to Image while making it more robust.
Hi, I followed the install instructions (http://intervention.olivervogel.net/image/getting_started/installation) , and I'm getting this error:
Class 'Intervention\Image\ImageServiceProvider' not found
I'm stuck with this. Any help will be appreciated.
In my use case I'd like to save the image and serve the result of that image to the client. Internally $this->encode is called. It would be nice to cache the result of that on the Image object and expose it.
Will this be a performance or memory hit?
[Proposal] Plugin Filter Architecture
As I have been working with the Image library, I have wanted to add additional methods that modified the image resource in a particular way. For purely illustration purposes, say I wanted to modify an image to be half grayscale and half color (HalfAndHalf).
class Image
{
# existing class code
public function halfAndHalf($direction = 'vertical')
{
# method code here
return $this;
}
}
To implement this functionality in the current architecture, I would have to modify the Image Class signature. I think this defeats the “Open and Closed” principle of SOLID (please correct me if I am mistaken).
I could extend the Image Class and add the new halfAndHalf functionality. But to me that gives off a code “smell”, because I would have to extend the class each time I wanted to add a new way to modify an image.
class HalfAndHalfImage extends Image
{
public function halfAndHalf($direction = 'vertical')
{
# method code here
return $this;
}
}
So my proposal is to create a “Plugin Filter Architecture”. In Gimp, there is menu option called “filters”, which apply things like blurs, distortions, etc. So I am calling classes that modify an image in some way, a filter to stay consistent with terminology.
The idea would include creating an ImageInterface with a simple signature that can be generally applied to the Image class. Example methods would be save, filter (more on filter below), and others. The Intervention\Image\Image would implement this interface.
The filter method should be implemented to type-hint for FilterInterface $objects.
In addition, a FilterInterface should be created with at least a single method, applyFilter. This method should be implemented to type-hint for objects that implement the ImageInterface.
So to tie the these two interfaces together see the code below:
interface ImageInterface
{
public function save($path = null, $quality = 90);
public function filter(FilterInterface $filter);
}
class Image implements ImageInterface
{
public function save($path = null, $quality = 90)
{
# method code
}
public function filter(FilterInterface $filter)
{
return $filter->applyFilter($this);
}
}
interface FilterInterface
{
public function applyFilter(ImageInterface $image);
}
class HalfAndHalfFilter implements FilterInterface
{
protected $direction;
public function __construct($direction = “vertical”)
{
$this->direction = $direction;
}
public function applyFilter(ImageInterface $image)
{
# apply filter to incoming image
return $image;
}
}
# to apply the filter to an image
$image = Image::make(‘img/foo.jpg’);
$image->filter(new HalfAndHalfFilter(‘horizontal’));
# plus method chaining one filter to another
$image->filter(new Filter())->filter(new AnotherFilter())->filter(new CropFilter());
# ----- or ------
$filter = new HalfAndHalfFilter(‘vertical’);
# a collection of image objects that need to have the filter applied
foreach ($imageCollection as $num => $img) {
$filter->applyFilter($img)->save(‘filtered_image.jpg’);
}
Some of the benefits of this approach would be:
Hopefully, this provides an idea of what I am thinking. If not we can discuss more.
Thanks for the great package first,but In Laravel 4 the code below is works well:
$file = Input::file('avatar');
$destinationPath ='img/avatar/';
$filename = date('YmdHis').rand(100,999).'.'.$file->getClientOriginalExtension();
$filepath = $destinationPath.$filename;
\Image::make($file->getRealPath())->resize(154,154)->save($filepath);
$profile->avatar = $filepath;
it can upload the image to public/img/avatar ,but if I change to
$destinationPath ='img/avatar/2/';
ImageNotWritableException then throwed.
Confused that.
Something gets wrong when you resize an image below 81 in width and height. I can view the file in Windows without problem, but when I try to display the image with PHP it doesn't work (outputs some jibberish text instead of the image).
I resize the image with this:
Image::make('path/to/file.jpg')->resize(80, 80)->save('newpath/to/file.jpg');
I display it in PHP with this:
header("Content-Type: image/jpg");
return readfile('newpath/to/file.jpg');
I know im missing something fundamental...
When using this package on a Laravel 4 instance. I do the following:
$user->image = Image::make(Input::file('image')->getRealPath())->resize(300, 200)->save('./uploads/foo.jpg');
Although ->save() does not return the path to my image. I know i have the path via what i entered in the save function, although i would like it returned via the function.
Am i missing something obvious?
It would be nice to add left/right alligment to the text function using the boundaries given by the imagettftext function as this comment:
http://www.php.net/manual/en/function.imagettftext.php#83248
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.