[wp-trac] [WordPress Trac] #23127: Media Upload hangs on Crunching on too big image sizes.

WordPress Trac noreply at wordpress.org
Thu Oct 17 15:58:21 UTC 2024


#23127: Media Upload hangs on Crunching on too big image sizes.
--------------------------+-----------------------------
 Reporter:  clubdesign    |       Owner:  (none)
     Type:  defect (bug)  |      Status:  new
 Priority:  normal        |   Milestone:  Future Release
Component:  Media         |     Version:  2.7
 Severity:  normal        |  Resolution:
 Keywords:                |     Focuses:
--------------------------+-----------------------------

Comment (by glynnquelch):

 During our investigation into a memory issue, we discovered that the
 control logic in wp-includes/class-wp-image-editor-gd.php causes
 imagecreatefromstring() to be called twice. This results in double the
 memory usage, especially when working with large images.

 {{{#!php
 <?php
 // WebP may not work with imagecreatefromstring().
 if (
  function_exists( 'imagecreatefromwebp' ) &&
  ( 'image/webp' === wp_get_image_mime( $this->file ) )
 ) {
  $this->image = @imagecreatefromwebp( $this->file );
 } else {
  $this->image = @imagecreatefromstring( $file_contents );
 }

 // AVIF may not work with imagecreatefromstring().
 if (
  function_exists( 'imagecreatefromavif' ) &&
  ( 'image/avif' === wp_get_image_mime( $this->file ) )
 ) {
  $this->image = @imagecreatefromavif( $this->file );
 } else {
  $this->image = @imagecreatefromstring( $file_contents );
 }
 }}}

 When handling the image above (test.jpg) im seeing

 2024-10-17 15:22:25] log: peak: 518.63 MB
 [2024-10-17 15:22:25] log: image/avif: 284.17 MB
 [2024-10-17 15:22:25] log: image/webp: 284.17 MB
 [2024-10-17 15:22:24] log: Memory usage at start: 49.73 MB
 [2024-10-17 15:22:23] log: peak: 488.60 MB
 [2024-10-17 15:22:23] log: image/avif: 254.14 MB
 [2024-10-17 15:22:23] log: image/webp: 254.14 MB
 [2024-10-17 15:22:23] log: Memory usage at start: 19.69 MB

 I log memory usage after the if statements and at the start/end

 IF that control logic was reduced to

 {{{#!php
 <?php
 // WebP may not work with imagecreatefromstring().
 if ( function_exists( 'imagecreatefromwebp' ) &&
         ( 'image/webp' === wp_get_image_mime( $this->file ) )
 ) {
         $this->image = @imagecreatefromwebp( $this->file );
 // AVIF may not work with imagecreatefromstring().
 } elseif ( function_exists( 'imagecreatefromavif' ) &&
         ( 'image/avif' === wp_get_image_mime( $this->file ) )
 ) {
         $this->image = @imagecreatefromavif( $this->file );
 } else {
         $this->image = @imagecreatefromstring( $file_contents );
 }
 }}}

 We see
 [2024-10-17 15:55:53] log: peak: 284.19 MB
 [2024-10-17 15:55:53] log: image/avif or image/webp: 284.17 MB
 [2024-10-17 15:55:53] log: Memory usage at start: 49.73 MB
 [2024-10-17 15:55:52] log: peak: 254.16 MB
 [2024-10-17 15:55:52] log: image/avif or image/webp: 254.14 MB
 [2024-10-17 15:55:51] log: Memory usage at start: 19.69 MB

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/23127#comment:29>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list