gumlet / php-image-resize Goto Github PK
View Code? Open in Web Editor NEWPHP library to resize, scale and crop images. Cloud solution available at:
Home Page: https://www.gumlet.com
License: MIT License
PHP library to resize, scale and crop images. Cloud solution available at:
Home Page: https://www.gumlet.com
License: MIT License
You are using function imageflip()
which available only since php 5.5, but minimum php version in composer.json set to 5.3. It can be problem for some fans of antiques.
Is Save() methods will save the image to folder?
I would like to use your great class in our commercial product, but I cannot find your licensed defined anywhere.
If no license is defined, the normal copyright (All rights reserved) comes into action and anybody - no matter if the usage is private or commercial - has to ask you.
So may I ask you if I can use it for our commercial product or set it generally under a license you prefer?
Thanks in advance and keep up your great work!
i didn't get your documentation how to start? do you have any video tutorial or examples?
You might want to add webp as an output format, GD supports it since php 5.5.
Hello!
When you resizing png with transparent background - it is important to maintain small file size.
For example:
It happens because of increasing amount of colors in palette. Under 1000 in original image / more than 8000 in resized.
Fast dirty hack to avoid it:
$image_type = $image_type ?: $this->source_type;
if($image_type == IMAGETYPE_PNG) {
$dest_image = imagecreate($this->getDestWidth(), $this->getDestHeight()); // not true color!
$alpha = imagecolorallocatealpha($dest_image, 255, 255, 255, 127); // fully transparent white color
imagefill($dest_image, 0, 0, $alpha); // fill image with transparent background
} else {
$dest_image = imagecreatetruecolor($this->getDestWidth(), $this->getDestHeight());
}
Maybe you will implement some sort of feature, based on this.
Hey guys (especially @adityapatadia),
I've just pushed up a bunch of commits related to the changes we discussed in #19.
It was meant to be a new PR, but accidentally just pushed it to master.
Should be pretty stable though, and still getting passing all tests with 100% CC.
But please let me know if we need to change anything before tagging.
Majority of API stays the same, just the new createFromString()
from @Sjaakmoes, which has been simplified a bit.
It would be nice if you could set the interlace property on or off on the output image.
http://php.net/manual/en/function.imageinterlace.php
I run into an very strange problem.
I have an upload script, that will be start through the form from the upload page. So, this script runs "stand alone". Then I have an import area in my project. This import is included into an other (main) file.
When I upload an file, everything is fine. ImageResize do what it should do.
When I import the images, I got this error message:
`
Fatal error: Uncaught Eventviva\ImageResize
Exception: Could not read file in /home/sites/dev/admin/classes/ImageResize.php:32
Stack trace:
#0 /home/sites/dev/admin/content_photo_import.php(130): Eventviva\ImageResize->__construct('/home/sites/dev...')
#1 /home/sites/dev/admin/dashboard.php(57): include('/home/sites/dev...')
#2 /home/sites/dev/admin/index.php(48): include('/home/sites/dev...')
#3 {main} thrown in /home/sites/dev/admin/classes/ImageResize.php on line 32
`
The path's are in both cases the same. The only different is, on the upload script I use "move_uploaded_file($tmp, $newFilePath" and on the import script, I use "copy($file, $newFilePath".
Any idea how to fix?
Regards
Torsten
thank you for this script & your hard work.
i am using your script in a php loop with an array of images to be uploaded and resize
since for each image, i will use the same variable
$image = new \Eventviva\ImageResize("$image_src");
(where $image_src is an image source which is run in php loop)
your script will not run on the next image. I am thinking it is because the $image is not being cleared for a new source
i tried:
$image = "";
unset($image);
and destroy($image)
but none of these work. How do i destroy & reuse the variable for a new image source?
i use quality_jpg to 10, but doesn't work
my code :
<?php
$image = new \Eventviva\ImageResize('img1.jpg');
$image->quality_jpg = 10;
$image->resize(215, 290);
$image->save('img2.jpg');
?>
Resize work, but not quality.
Hi there,
Is there any way to compress the image setting, for example, as max file size 5 MB instead of setting quality parameter?
Thanks in advance
I have the following error message in firebug when I upload the photos, it works fine locally
Fatal error: Uncaught exception 'Exception' with message 'Could not read file' in /home/sites/wightwarriors
.co/public_html/tapesup/include/ImageResize.php:68
Stack trace:
#0 /home/sites/wightwarriors.co/public_html/tapesup/photos/upload.php(42): Eventviva\ImageResize->__construct
('http://www.wigh...')
#1 {main}
thrown in /home/sites/wightwarriors.co/public_html/tapesup/include/ImageResize.php on line 68
I am loading and sizing images, however if I specify quality the image gets a file size of 0. This happens when I use $image->quality_png = 50;
and $image->save($tmp_name, IMAGETYPE_PNG, 50);
But the images export fine with out setting a quality.
My code:
$image = new \Eventviva\ImageResize($_FILES['file']['tmp_name']);
$image->resizeToBestFit($image_size[0], $image_size[0]);
$image->save($tmp_name, IMAGETYPE_PNG, 50);
Hey, thanks for an awesome package!
Is there the ability to greyscale an image? If not, could it be a possible enhancement?
Thanks!
I'd like to see this library get updated to utilize PSR standards.
One major thing I've noticed is that part of the library utilizes tab characters and others utilize 4 space indentation.
If I get a little free time, I will happily take a look at updating all of the variables, method definitions, spaces, etc... and put in a PR. I just want to know if there is any support for this from the maintainers. 1 or 2 thumbs up will be enough for me to put this on my "to-do" list.
eventviva/php-image-resize: 1.6.1
Fatal error: Uncaught exception 'Exception' with message 'Could not read file' in D:\xampp\htdocs
\folder\vendor\eventviva\php-image-resize\lib\ImageResize.php:68
#0: Eventviva\ImageResize->__construct('')
#2: call_user_func_array(Array, Array)
thrown in <b>D:\xampp\htdocs\folder\vendor\eventviva\php-image-resize\lib\ImageResize.php on line 68
Try upload this img http://www.letsgodigital.org/images/producten/1830/testrapport/alpha-test-photo.jpg
require ROOT . '/vendor/autoload.php';
$tempImg = $_FILES['file']['tmp_name'];
$image= new \Eventviva\ImageResize($tempImg );
$image->quality_jpg = 60;
$image->save($dir . $imgName, IMAGETYPE_JPEG)
when I upload a picture I get the following error
Fatal error: Call to undefined function Eventviva\exif_read_data()
../vendor/eventviva/php-image-resize/src/ImageResize.php on line 106
Some thoughts about support an watermark ? Could I do pull request ?
I get the following error:
Fatal error:
Uncaught exception 'Eventviva\ImageResizeException' with message 'File does not exist' in /home/mysite/public_html/inc/imageresize.php:72
Stack trace:
#0 /home/mysite/public_html/inc/savephotos.php(54): Eventviva\ImageResize->__construct('')
#1 /home/mysite/public_html/my-details/mydetails/myhome/photosandpanoramas.php(17): include('/home/mysite/pu...')
#2 {main} thrown in /home/mysite/public_html/inc/imageresize.php on line 72
This only appears with larger files - I am testing with an image 3.5M, which will be resized after uploading. I followed up with a 708k file which uploaded without issue.
Users can upload up to 8 images, and sometime use files as large as 6 or 7Mb, so the server is set to
post_max_size 70M
upload_max_filesize 8M
I understand that the file may be in a different place to the expected place - but I can't see how to find what the filename currently is, or where it should be! And, if a smaller file gets through, then I think that is less likely to be the issue.
The class looks fine. It would be a benefit to have a caching feature. It could be based on a CONST save_path. If it is set, it can check if the image exists. If it does, directly return the image.
Optional: A no_cache on the API request in case of new settings for the same dimensions while maintaining a save_path.
It would greatly expand on projects this class could be used for.
When I upload a jpg using the class my site errors and goes to a blank screen (no error message). The class works fine on my local dev environment, it only breaks on the remote host, and only then when uploading jpgs.
When opening an image with incorrect EXIF-data, the error "Incorrect APP1 Exif Identifier Code" occurs (just a warning, but still).
A silencer for exif_read_data() would fix this. File: ImageResize.php, Line: 106
@see http://stackoverflow.com/questions/8106683/exif-read-data-incorrect-app1-exif-identifier-code
Hi,
I've tried to resize PNG image to the smaller size (with resizeToWidth) but the resulting image was extremely big. When I've used image compress tool (ImageOptim) it was able to remove 99% of the image size so there must be too much bloating information in the image.
$image = ImageResize::createFromString( file_get_contents( $data['thumb'] ) ) ) {
$full = $image->resizeToWidth( 800 )->crop( 800, 420 )->getImageAsString( IMAGETYPE_JPEG, 100 );
Above code creates an image that is identical to the original. the original size is around 480px, the image is never scaled up and also not cut. is there some some of issue if the image is smaller than the resize to width?
Would be great if PNG supported the imagesavealpha
function.
If it's not something you want to poke at, I'll look at the code. Should be easy enough to implement. ๐ป
This is a great tool, thanks for developing this module.
I have encountered some bugs however. I hope it would improve the current code base. I noticed in one of the recent commits - errors are suppressed. However, there are other areas of the code where errors need to be suppressed.
I have added the setting below. However, I do understand that errors are useful in development (not production!) settings.
ini_set ('gd.jpeg_ignore_warning', 1);
I also encountered an memory limit specifically related to the following code block. The imagerotate function bugs out when the memory limit exceeds 94371840 bytes. So I have also included the setting below.
ini_set('memory_limit', '300M'); // add this
if ($orientation === 6 || $orientation === 5){
$img = imagerotate($img, 270, null);
...
Perhaps this module could include some sort of logic around these two cases. Most PHP frameworks provide an environment variable, perhaps this can be hooked in somewhere.
how to integrated it with cakephp?
when $image->output()
its error with cakephp header. Cannot dispaly the image.
thanks
Hello, trying to us your library but every file fails to resizewith an error like the following, happening with both png and jpeg images
[Mon Jan 8 11:15:26 2018] PHP Fatal error: Uncaught Error: Call to undefined function Eventviva\imagecreatefrompng() in /php/ImageResize.php:112
Stack trace:
#0 /upload.php(48): Eventviva\ImageResize->__construct('/tmp/phpV0fAfB')
#1 {main}
thrown in /php/ImageResize.php on line 112
[Mon Jan 8 11:15:26 2018] 192.168.1.149:33896 [500]: /upload.php - Uncaught Error: Call to undefined function Eventviva\imagecreatefrompng() in /php/ImageResize.php:112
Stack trace:
#0 /upload.php(48): Eventviva\ImageResize->__construct('/tmp/phpV0fAfB')
#1 {main}
thrown in /php/ImageResize.php on line 112
is this a bug or am I doing something wrong?
$image = ImageResize::createFromString(base64_decode('base64_GIF_Image_Data'));
$image->resize(500, 500);
$image->save('image.gif', IMAGETYPE_GIF);
GIF not working
Image is saving but animation not working
Can this function be used to pull a remote file? In other words, I want to pull an image from a url not from disk.
$image = new ImageResize('http://domain.com/AC1138558928.jpg');
Hi all,
I hope you re all fine .
I need help to use your library.
I don't user composer so I do as you mentioned :
" ...
Otherwise:
include '/path/to/ImageResize.php';
Because this class uses namespacing, when instantiating the object, you need to either use the fully qualified namespace:
$image = new \Eventviva\ImageResize();
..."
At this line I get a 500 Internal Server Error :
$image = new \Eventviva\ImageResize();
OR when I alias it
use \Eventviva\ImageResize;
$image = new ImageResize(); <--- this line
I included this way:
include "../../../includes/imageResize/lib/ImageResize.php";
use \Eventviva\ImageResize;
Is the something I missed ?
Thank you in advance for your answer.
$image_info = @getimagesize($filename); in method __construct fails if allow_url_fopen is Off is php.ini, when using createFromString
this can be fixed with using getimagesizefromstring() in createFromString and transferring the data to __construct
My entry filename was "p18mq5j9k2op6amc1pngp1u1da37.png" and after I started
$image_object->save(p18mq5j9k2op6amc1pngp1u1da37.png, IMAGETYPE_JPEG,90);
filename turned to "p18mq5j9k2op6amc1jpgp1u1da37.jpg". Notice that there are two replacements in filename. I supposed that save() method can replace only the extension part of the filename.
How can I fix this issue?
Which algorithm(s) are used for the resampling / interpolation?
Bicubic, bilinear, nearest neighbour, etc.?
Is it possible to change it?
I am trying to add webp image file type like
elseif ($this->image_type == IMAGETYPE_WEBP) {
$this->image = imagecreatefrompng($filename);
}
but it gives me error. could anyone tell me how to add webp file type?
You might want to use oyejorge/less.php as a dependency instead of your outdated copy.
I'm having issues to generate a thumbnail from a Transparent PNG.
Someone have some idea how to solve this problem?
Firstly, Just want to say I love this package. Its simple and does exactly what I need without having to worry about anything.
The only thing that I have noticed is that with using this package it take away any animation from a gif. Is there any plan to support animated gifs in the future?
Hi
Thank you for a nice resizing tool. Would be great if you are able crop the image at a random position, i.e a method like this:
public function crop($width, $height, $source_x, $source_y) {}
This will make this tool compatible with this client side cropping script: http://www.croppic.net/
The function getImageAsString
saves the image to a temporary file on disk, just to read it again. This is not optimal. You can get the result in a string by using output buffering.
<?php
ob_start();
imagepng($image);
$image_data = ob_get_contents();
ob_end_clean();
I'm developing an application where the image has to have a max width or max height. This way it will always be scaled correctly. Now I can enforce a width and height but it won't keep the aspect ratio.
Since I do not know in advance what the aspect ratio of the image is I cannot determine how the image should be scaled.
Lets say I have a frame that is 145w and 90h (maximum dimensions). If i use resize it will force the image in this frame, rather than computing how much it should remove on either one dimension.
when i try to instanciate a new ResizeImage object i got this error. "The file eventviva\imageresize.php could not be found."
isn't it better to get file handler instead of filename to save image to ?
or maybe another way .
but I need an approach to save my image in temp or memory.
See https://eventviva.github.io/php-image-resize/class-Eventviva.ImageResize.html#_crop
optional params $postion and $allow_enlarge should be switched.
I am trying to resize a gif file but animation is destroyed.
<?php
require 'vendor/autoload.php';
$image = new \Eventviva\ImageResize("img/1460392243.gif");
var_dump($image);
$image->resizeToBestFit(500, 300);
$image->save("img/" . time().".gif");
?>
Please help !
It seems that png images are nog losslessly.
The fact is that Google PageSpeed is complaining about it.
Do you think GD is able to do this ?
exif_read_data() can sometimes generate errors and should be suppressed. The same suggestion is made in a comment to the SE post that served as inspiration for the imageCreateJpegfromExif() method.
/**
* Gets crop position (X or Y) according to the given position
*
* @param integer $expectedSize
* @param integer $position
* @return integer
*/
protected function getCropPosition($expectedSize, $position = self::CROPCENTER)
{
$size = 0;
switch ($position) {
case self::CROPBOTTOM:
case self::CROPRIGHT:
$size = $expectedSize;
break;
case self::CROPCENTER:
case self::CROPCENTRE:
$size = $expectedSize / 2;
break;
case self::CROPTOPCENTER:
$size = $expectedSize / 4;
break;
}
return $size;
}
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.