[wp-trac] [WordPress Trac] #62331: Imaged Edit GD Control Flow
WordPress Trac
noreply at wordpress.org
Fri Nov 1 11:03:19 UTC 2024
#62331: Imaged Edit GD Control Flow
--------------------------+-----------------------------
Reporter: glynnquelch | Owner: (none)
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Media | Version: trunk
Severity: normal | Keywords: needs-patch
Focuses: |
--------------------------+-----------------------------
I referenced this on a similar issue
https://core.trac.wordpress.org/ticket/23127#comment:29
When the imagecreatefromstring() function is called in wp-includes/class-
wp-image-editor-gd.php, it will often call this function twice. This often
results in serious memory issues for larger images and at some formats it
doubles the memory used
{{{#!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 );
}
}}}
If I make a change locally 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 );
}
}}}
I see a reduction in the memory overhead
||= Filename =||= Size (W x H) =||= Filesize =||= Current GD Peak Memory
=||= Improved Flow Peak Memory =||
||Suru_Bog_10000px.jpg||10000 x 4534||33.08 MB||410.41 MB||266 MB||
||test.jpg||7500 x 7500||1.75 MB||510.02 MB||308.71 MB||
||156442-ultra-widescreen-wallpaper.jpg||4500 x 1901||642.36 KB||96.98
MB||92.96 MB||
||logo.png||1024 x 512||85.47 KB||20.36 MB||10.29 MB||
||Sample-10345x5531.webp||10345 x 3989||7.49MB||378.79 MB||207.38MB||
||minion-large.webp||10000 x 5000||2.15MB||419.38 MB||224.05MB||
||minion-large.gif||25000 x 12500||25.84MB||734.04 MB||424.89MB||
||SamplePNGImage_30mbmb.png||7345 x 2832||31.39MB||297.11 MB||241.41MB||
||IMG_20211115_123549.jpg||4624 x 3472||2.57 MB||167.69 MB||132.58MB||
Some smaller images see no difference and some gifs use more memory at
times, but for images with larger dimensions, we see memory allocation
errors with hosts that limit memory at 512mb of ram.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/62331>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list