Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

unnormal memory usage (x4) #1278

Closed
a-shafaat opened this issue Jan 22, 2024 · 7 comments
Closed

unnormal memory usage (x4) #1278

a-shafaat opened this issue Jan 22, 2024 · 7 comments

Comments

@a-shafaat
Copy link

a-shafaat commented Jan 22, 2024

Describe the bug
reading images uses a lot more memory than it should. reading a 2 MB image using GD uses only 160 MB but the library uses 545mb!

Code Example
$manager = new ImageManager(new Driver());
$image = $manager->read($filePath, FilePathImageDecoder::class); // 545mb memory peak
vs
$image = imagecreatefromjpeg($filePath); // 160mb memory peak

Expected behavior
lower memory usage (near 160MB)

Images

Environment (please complete the following information):

  • PHP Version: 8.2
  • OS: alpine (k8s)
  • Intervention Image Version: 3.3.0
  • GD or Imagick: GD
@olivervogel
Copy link
Member

Thanks for your report. This is already addressed in #1269

@olivervogel
Copy link
Member

reading a 2 MB image using GD uses only 160 MB

Reading a 2 MB image with GD used 5.70 MB in a example I just created. How did you calculate these values?

@a-shafaat
Copy link
Author

I'm using symfony framework. The symfony framework has a web GUI profiler with a performance tab that shows peak memory usage and some other related info.

Screenshot 2024-01-23 010653

@a-shafaat
Copy link
Author

the image i have used:
https://cdn.tizbam.ir/600dpi_Page_1.jpg

@olivervogel
Copy link
Member

olivervogel commented Jan 23, 2024

Thanks. The topic will be pursued further here.

@olivervogel
Copy link
Member

One more note: The decoding process of Intervention Image involves more than just opening the image. The following tasks are performed:

  • Extraction of EXIF data for appropriate formats
  • Adjust the image rotation according to the EXIF data.

In your example image, the image rotation is set to 6 in the EXIF data. This means that the image is rotated once by 270 degrees to make so it is aligned correctly. This can take a lot of memory for large image sizes, especially with GD.

The examples from your code samples are therefore not 1:1 comparable.

@a-shafaat
Copy link
Author

thanks for your notes. I think any further processing must be optional and developers should be able to ignore them with a flag or some other way.
in my case, as you may guessed already, I want to do some OMR, and most of the work is done in another environment (python + opencv + ...). In php part of my environment, I only want to resize the picture if it's larger than 3000 pixels in any dimension and convert it to webp.
The Python part has some computer vision capabilities and can recognize the rotations. so exif rotation is a redundancy for me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants