image
image copied to clipboard
File size increases almost 300%
I have been running into the issue where if a user uploads an jpeg and we store it via Image::make(img-data) and then $image->save(....); The file size increases almost 300%. For example, I uploaded a 323mb file and it uploaded as a 900mb file.
Does saving it out at the default 90% quality increase file size even if the image was optimized before being uploaded?
Pictures of code?
Greetings
Hi,
With Glide : https://github.com/thephpleague/glide when I run :
$server->outputImage($path, []);
My image size too increases around 200% or 300%.
Glide related code is here :
https://github.com/thephpleague/glide/blob/master/src/Server.php#L461
An example image :
https://68.media.tumblr.com/80f9f86a4db07102a44851b46aa01788/tumblr_opajjcPvjs1vwae5go1_1280.jpg
I'm running into the same issue where my images filesize is being increased by 300% when using $image->save(....);
- does anyone know whats going on?
I have the same issue:
public static function resizeWithFallback($img, $width, $height, $new_name = false, $quality = 90){
$new_name = (!empty($new_name)) ? $new_name : $img;
$imgHandler = Image::make($img);
$imgHandler->orientate();
$old = array(
'filesize' => $imgHandler->filesize(),
'width' => $imgHandler->width(),
'height' => $imgHandler->height()
);
$imgHandler->widen($width, function ($constraint) {
$constraint->aspectRatio();
$constraint->upsize();
})->heighten($height, function ($constraint) {
$constraint->aspectRatio();
$constraint->upsize();
});
$imgHandler->save($new_name, $quality);
$status = array(
'status' => true,
'filename' => $new_name
);
if(file_exists($new_name) && $imgHandler->filesize() >= $old['filesize'] && ($old['width'] == $imgHandler->width() && $old['height'] == $imgHandler->height())){
if($new_name != $img) {
unlink($new_name);
}
$status = array(
'status' => false,
'filename' => $img,
'debug' => array(
'old' => $old,
'new' => array(
'filesize' => $imgHandler->filesize(),
'width' => $imgHandler->width(),
'height' => $imgHandler->height()
)
)
);
}
return $status;
}
I'm trying this code, what do you think about? basically it check filesize, width and height and if new image is not good it remove and return the old one
This is still an issue, it is not handling the file as I would expect... Here is some example code and steps to repeat (really.. save any image with 100 quality)
- Grab any image
- Run script below
<?php
$fileopen = __DIR__.'/testimage.jpg';
$filesave = __DIR__.'/testimage_saved.jpg';
// report file size
clearstatcache();
$filesize = filesize($fileopen);
echo "Current file size: {$filesize}\n";
// load image and save it immediately
require 'vendor/autoload.php';
use Intervention\Image\ImageManager;
$manager = new ImageManager(array('driver' => 'gd'));
$image = $manager->make($fileopen);
$image->save($filesave, 100);
// report file size
clearstatcache();
$newsize = filesize($filesave);
echo "Current file size: {$newsize}\n";
// report increase
$increase = round(($newsize / $filesize) * 100, 5);
echo "Increase = {$increase}%\n";
Output:
Current file size: 1138320
Current file size: 2960342
Increase = 260.06237%

- Expected: File size to be the same, or a very very small difference
- Result: File size increases dramatically
Not sure on cause, maybe file system? (I'm on a mac), maybe GD library? Who knows.
What this means is that if you do: $image->save($filesave, 80);
it will be "80% quality of whatever quality intervention is currently at and not 80% quality of the original?
Output with 80%
Current file size: 1138320
Current file size: 1261386
Increase = 110.8112%
I understand there will be some processing added and the algorithm Intervention uses, however 260% is a bit crazy. I don't think the original MS paint was that bad :D
If you are you using GD, it may be caused by what is described by this answer.
A solution could be switching to ImageMagick.
Having the same issue. but after using the below method almost done my problem.
$file = Image::make($file)->resize(800, null, function ($constraint) {$constraint->aspectRatio();});
I have the same problem. I solve it by using quality 60 - 80.
Jan 9, 2023. The issue still exists. Driver: Imagick. It is enough to save at 100% quality to reproduce. Any suggestions?
I have been running into the issue where if a user uploads an jpeg and we store it via Image::make(img-data) and then $image->save(....); The file size increases almost 300%. For example, I uploaded a 323mb file and it uploaded as a 900mb file.
Does saving it out at the default 90% quality increase file size even if the image was optimized before being uploaded?
Facing same issue but not suitable solution founded
The same issue (