<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[48798] trunk: Code Modernization: Introduce `is_gd_image()` to check for PHP 8 `GdImage` object instances.</title>
</head>
<body>
<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { white-space: pre-line; overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta" style="font-size: 105%">
<dt style="float: left; width: 6em; font-weight: bold">Revision</dt> <dd><a style="font-weight: bold" href="https://core.trac.wordpress.org/changeset/48798">48798</a><script type="application/ld+json">{"@context":"http://schema.org","@type":"EmailMessage","description":"Review this Commit","action":{"@type":"ViewAction","url":"https://core.trac.wordpress.org/changeset/48798","name":"Review Commit"}}</script></dd>
<dt style="float: left; width: 6em; font-weight: bold">Author</dt> <dd>SergeyBiryukov</dd>
<dt style="float: left; width: 6em; font-weight: bold">Date</dt> <dd>2020-08-16 13:31:57 +0000 (Sun, 16 Aug 2020)</dd>
</dl>
<pre style='padding-left: 1em; margin: 2em 0; border-left: 2px solid #ccc; line-height: 1.25; font-size: 105%; font-family: sans-serif'>Code Modernization: Introduce `is_gd_image()` to check for PHP 8 `GdImage` object instances.
In PHP 8, the GD extension uses `GdImage` objects instead of resources for its underlying data structures.
This updates the existing `is_resource()` calls for image resources in core to accomodate for `GdImage` instances as well.
Props ayeshrajans, jrf.
Fixes <a href="https://core.trac.wordpress.org/ticket/50833">#50833</a>.</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunksrcwpadminincludesimageeditphp">trunk/src/wp-admin/includes/image-edit.php</a></li>
<li><a href="#trunksrcwpadminincludesimagephp">trunk/src/wp-admin/includes/image.php</a></li>
<li><a href="#trunksrcwpincludesclasswpimageeditorgdphp">trunk/src/wp-includes/class-wp-image-editor-gd.php</a></li>
<li><a href="#trunksrcwpincludesclasswpimageeditorimagickphp">trunk/src/wp-includes/class-wp-image-editor-imagick.php</a></li>
<li><a href="#trunksrcwpincludesdeprecatedphp">trunk/src/wp-includes/deprecated.php</a></li>
<li><a href="#trunksrcwpincludesmediaphp">trunk/src/wp-includes/media.php</a></li>
<li><a href="#trunktestsphpunittestsimagefunctionsphp">trunk/tests/phpunit/tests/image/functions.php</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunksrcwpadminincludesimageeditphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-admin/includes/image-edit.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-admin/includes/image-edit.php 2020-08-15 20:54:46 UTC (rev 48797)
+++ trunk/src/wp-admin/includes/image-edit.php 2020-08-16 13:31:57 UTC (rev 48798)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -291,8 +291,8 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * @since 2.9.0
</span><span class="cx" style="display: block; padding: 0 10px"> * @deprecated 3.5.0 Use {@see 'image_editor_save_pre'} instead.
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @param resource $image Image resource to be streamed.
- * @param int $attachment_id The attachment post ID.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @param resource|GdImage $image Image resource to be streamed.
+ * @param int $attachment_id The attachment post ID.
</ins><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> $image = apply_filters_deprecated( 'image_save_pre', array( $image, $attachment_id ), '3.5.0', 'image_editor_save_pre' );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -420,19 +420,22 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * @see WP_Image_Editor::rotate()
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @ignore
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @param resource $img Image resource.
- * @param float|int $angle Image rotation angle, in degrees.
- * @return resource|false GD image resource, false otherwise.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @param resource|GdImage $img Image resource.
+ * @param float|int $angle Image rotation angle, in degrees.
+ * @return resource|GdImage|false GD image resource or GdImage instance, false otherwise.
</ins><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> function _rotate_image_resource( $img, $angle ) {
</span><span class="cx" style="display: block; padding: 0 10px"> _deprecated_function( __FUNCTION__, '3.5.0', 'WP_Image_Editor::rotate()' );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
</ins><span class="cx" style="display: block; padding: 0 10px"> if ( function_exists( 'imagerotate' ) ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $rotated = imagerotate( $img, $angle, 0 );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ( is_resource( $rotated ) ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+ if ( is_gd_image( $rotated ) ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> imagedestroy( $img );
</span><span class="cx" style="display: block; padding: 0 10px"> $img = $rotated;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
</ins><span class="cx" style="display: block; padding: 0 10px"> return $img;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -444,17 +447,19 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * @see WP_Image_Editor::flip()
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @ignore
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @param resource $img Image resource.
- * @param bool $horz Whether to flip horizontally.
- * @param bool $vert Whether to flip vertically.
- * @return resource (maybe) flipped image resource.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @param resource|GdImage $img Image resource or GdImage instance.
+ * @param bool $horz Whether to flip horizontally.
+ * @param bool $vert Whether to flip vertically.
+ * @return resource|GdImage (maybe) flipped image resource or GdImage instance.
</ins><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> function _flip_image_resource( $img, $horz, $vert ) {
</span><span class="cx" style="display: block; padding: 0 10px"> _deprecated_function( __FUNCTION__, '3.5.0', 'WP_Image_Editor::flip()' );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
</ins><span class="cx" style="display: block; padding: 0 10px"> $w = imagesx( $img );
</span><span class="cx" style="display: block; padding: 0 10px"> $h = imagesy( $img );
</span><span class="cx" style="display: block; padding: 0 10px"> $dst = wp_imagecreatetruecolor( $w, $h );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ( is_resource( $dst ) ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+ if ( is_gd_image( $dst ) ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> $sx = $vert ? ( $w - 1 ) : 0;
</span><span class="cx" style="display: block; padding: 0 10px"> $sy = $horz ? ( $h - 1 ) : 0;
</span><span class="cx" style="display: block; padding: 0 10px"> $sw = $vert ? -$w : $w;
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -465,6 +470,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> $img = $dst;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
</ins><span class="cx" style="display: block; padding: 0 10px"> return $img;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -474,21 +480,23 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * @since 2.9.0
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @ignore
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @param resource $img Image resource.
- * @param float $x Source point x-coordinate.
- * @param float $y Source point y-coordinate.
- * @param float $w Source width.
- * @param float $h Source height.
- * @return resource (maybe) cropped image resource.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @param resource|GdImage $img Image resource or GdImage instance.
+ * @param float $x Source point x-coordinate.
+ * @param float $y Source point y-coordinate.
+ * @param float $w Source width.
+ * @param float $h Source height.
+ * @return resource|GdImage (maybe) cropped image resource or GdImage instance.
</ins><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> function _crop_image_resource( $img, $x, $y, $w, $h ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $dst = wp_imagecreatetruecolor( $w, $h );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ( is_resource( $dst ) ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+ if ( is_gd_image( $dst ) ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> if ( imagecopy( $dst, $img, 0, 0, $x, $y, $w, $h ) ) {
</span><span class="cx" style="display: block; padding: 0 10px"> imagedestroy( $img );
</span><span class="cx" style="display: block; padding: 0 10px"> $img = $dst;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
</ins><span class="cx" style="display: block; padding: 0 10px"> return $img;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -502,7 +510,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * @return WP_Image_Editor WP_Image_Editor instance with changes applied.
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> function image_edit_apply_changes( $image, $changes ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ( is_resource( $image ) ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( is_gd_image( $image ) ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> /* translators: 1: $image, 2: WP_Image_Editor */
</span><span class="cx" style="display: block; padding: 0 10px"> _deprecated_argument( __FUNCTION__, '3.5.0', sprintf( __( '%1$s needs to be a %2$s object.' ), '$image', 'WP_Image_Editor' ) );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -566,7 +574,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * @param array $changes Array of change operations.
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> $image = apply_filters( 'wp_image_editor_before_change', $image, $changes );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- } elseif ( is_resource( $image ) ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ } elseif ( is_gd_image( $image ) ) {
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="cx" style="display: block; padding: 0 10px"> * Filters the GD image resource before applying changes to the image.
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -574,8 +582,8 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * @since 2.9.0
</span><span class="cx" style="display: block; padding: 0 10px"> * @deprecated 3.5.0 Use {@see 'wp_image_editor_before_change'} instead.
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @param resource $image GD image resource.
- * @param array $changes Array of change operations.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @param resource|GdImage $image GD image resource or GdImage instance.
+ * @param array $changes Array of change operations.
</ins><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> $image = apply_filters_deprecated( 'image_edit_before_change', array( $image, $changes ), '3.5.0', 'wp_image_editor_before_change' );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span></span></pre></div>
<a id="trunksrcwpadminincludesimagephp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-admin/includes/image.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-admin/includes/image.php 2020-08-15 20:54:46 UTC (rev 48797)
+++ trunk/src/wp-admin/includes/image.php 2020-08-16 13:31:57 UTC (rev 48798)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -913,14 +913,38 @@
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * Determines whether the value is an acceptable type for GD image functions.
+ *
+ * In PHP 8.0, the GD extension uses GdImage objects for its data structures.
+ * This function checks if the passed value is either a resource of type `gd`
+ * or a GdImage object instance. Any other type will return false.
+ *
+ * @since 5.6.0
+ *
+ * @param resource|GdImage|false $image A value to check for the type for.
+ * @return bool True if $image is either a GD image resource or GdImage instance,
+ * false otherwise.
+ */
+function is_gd_image( $image ) {
+ if ( is_resource( $image ) && 'gd' === get_resource_type( $image )
+ || is_object( $image ) && $image instanceof GdImage
+ ) {
+ return true;
+ }
+
+ return false;
+}
+
+/**
</ins><span class="cx" style="display: block; padding: 0 10px"> * Load an image resource for editing.
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @since 2.9.0
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @param string $attachment_id Attachment ID.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @param string $mime_type Image mime type.
- * @param string $size Optional. Image size, defaults to 'full'.
- * @return resource|false The resulting image resource on success, false on failure.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @param string $mime_type Image mime type.
+ * @param string $size Optional. Image size. Default 'full'.
+ * @return resource|GdImage|false The resulting image resource or GdImage instance on success,
+ * false on failure.
</ins><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> function load_image_to_edit( $attachment_id, $mime_type, $size = 'full' ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $filepath = _load_image_to_edit_path( $attachment_id, $size );
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -942,22 +966,25 @@
</span><span class="cx" style="display: block; padding: 0 10px"> $image = false;
</span><span class="cx" style="display: block; padding: 0 10px"> break;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ( is_resource( $image ) ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+ if ( is_gd_image( $image ) ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="cx" style="display: block; padding: 0 10px"> * Filters the current image being loaded for editing.
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @since 2.9.0
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @param resource $image Current image.
- * @param string $attachment_id Attachment ID.
- * @param string $size Image size.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @param resource|GdImage $image Current image.
+ * @param string $attachment_id Attachment ID.
+ * @param string $size Image size.
</ins><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> $image = apply_filters( 'load_image_to_edit', $image, $attachment_id, $size );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
</ins><span class="cx" style="display: block; padding: 0 10px"> if ( function_exists( 'imagealphablending' ) && function_exists( 'imagesavealpha' ) ) {
</span><span class="cx" style="display: block; padding: 0 10px"> imagealphablending( $image, false );
</span><span class="cx" style="display: block; padding: 0 10px"> imagesavealpha( $image, true );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
</ins><span class="cx" style="display: block; padding: 0 10px"> return $image;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -971,7 +998,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * @access private
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @param string $attachment_id Attachment ID.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @param string $size Optional. Image size, defaults to 'full'.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @param string $size Optional. Image size. Default 'full'.
</ins><span class="cx" style="display: block; padding: 0 10px"> * @return string|false File path or url on success, false on failure.
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> function _load_image_to_edit_path( $attachment_id, $size = 'full' ) {
</span></span></pre></div>
<a id="trunksrcwpincludesclasswpimageeditorgdphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-includes/class-wp-image-editor-gd.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/class-wp-image-editor-gd.php 2020-08-15 20:54:46 UTC (rev 48797)
+++ trunk/src/wp-includes/class-wp-image-editor-gd.php 2020-08-16 13:31:57 UTC (rev 48798)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -17,7 +17,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="cx" style="display: block; padding: 0 10px"> * GD Resource.
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @var resource
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @var resource|GdImage
</ins><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> protected $image;
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -95,7 +95,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $this->image = @imagecreatefromstring( file_get_contents( $this->file ) );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ( ! is_resource( $this->image ) ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( ! is_gd_image( $this->image ) ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> return new WP_Error( 'invalid_image', __( 'File is not an image.' ), $this->file );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -138,12 +138,12 @@
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="cx" style="display: block; padding: 0 10px"> * Resizes current image.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * Wraps _resize, since _resize returns a GD Resource.
</del><span class="cx" style="display: block; padding: 0 10px"> *
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * At minimum, either a height or width must be provided.
- * If one of the two is set to null, the resize will
- * maintain aspect ratio according to the provided dimension.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * Wraps `::_resize()` which returns a GD resource or GdImage instance.
</ins><span class="cx" style="display: block; padding: 0 10px"> *
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * At minimum, either a height or width must be provided. If one of the two is set
+ * to null, the resize will maintain aspect ratio according to the provided dimension.
+ *
</ins><span class="cx" style="display: block; padding: 0 10px"> * @since 3.5.0
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @param int|null $max_w Image width.
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -158,7 +158,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $resized = $this->_resize( $max_w, $max_h, $crop );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ( is_resource( $resized ) ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( is_gd_image( $resized ) ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> imagedestroy( $this->image );
</span><span class="cx" style="display: block; padding: 0 10px"> $this->image = $resized;
</span><span class="cx" style="display: block; padding: 0 10px"> return true;
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -174,7 +174,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * @param int $max_w
</span><span class="cx" style="display: block; padding: 0 10px"> * @param int $max_h
</span><span class="cx" style="display: block; padding: 0 10px"> * @param bool|array $crop
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @return resource|WP_Error
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @return resource|GdImage|WP_Error
</ins><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> protected function _resize( $max_w, $max_h, $crop = false ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $dims = image_resize_dimensions( $this->size['width'], $this->size['height'], $max_w, $max_h, $crop );
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -188,7 +188,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> $resized = wp_imagecreatetruecolor( $dst_w, $dst_h );
</span><span class="cx" style="display: block; padding: 0 10px"> imagecopyresampled( $resized, $this->image, $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ( is_resource( $resized ) ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( is_gd_image( $resized ) ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> $this->update_size( $dst_w, $dst_h );
</span><span class="cx" style="display: block; padding: 0 10px"> return $resized;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -329,7 +329,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> imagecopyresampled( $dst, $this->image, 0, 0, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ( is_resource( $dst ) ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( is_gd_image( $dst ) ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> imagedestroy( $this->image );
</span><span class="cx" style="display: block; padding: 0 10px"> $this->image = $dst;
</span><span class="cx" style="display: block; padding: 0 10px"> $this->update_size();
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -353,7 +353,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> $transparency = imagecolorallocatealpha( $this->image, 255, 255, 255, 127 );
</span><span class="cx" style="display: block; padding: 0 10px"> $rotated = imagerotate( $this->image, $angle, $transparency );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ( is_resource( $rotated ) ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( is_gd_image( $rotated ) ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> imagealphablending( $rotated, true );
</span><span class="cx" style="display: block; padding: 0 10px"> imagesavealpha( $rotated, true );
</span><span class="cx" style="display: block; padding: 0 10px"> imagedestroy( $this->image );
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -362,6 +362,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> return true;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
</ins><span class="cx" style="display: block; padding: 0 10px"> return new WP_Error( 'image_rotate_error', __( 'Image rotate failed.' ), $this->file );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -379,7 +380,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> $h = $this->size['height'];
</span><span class="cx" style="display: block; padding: 0 10px"> $dst = wp_imagecreatetruecolor( $w, $h );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ( is_resource( $dst ) ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( is_gd_image( $dst ) ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> $sx = $vert ? ( $w - 1 ) : 0;
</span><span class="cx" style="display: block; padding: 0 10px"> $sy = $horz ? ( $h - 1 ) : 0;
</span><span class="cx" style="display: block; padding: 0 10px"> $sw = $vert ? -$w : $w;
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -391,6 +392,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> return true;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
</ins><span class="cx" style="display: block; padding: 0 10px"> return new WP_Error( 'image_flip_error', __( 'Image flip failed.' ), $this->file );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -415,9 +417,9 @@
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @param resource $image
- * @param string|null $filename
- * @param string|null $mime_type
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @param resource|GdImage $image
+ * @param string|null $filename
+ * @param string|null $mime_type
</ins><span class="cx" style="display: block; padding: 0 10px"> * @return array|WP_Error
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> protected function _save( $image, $filename = null, $mime_type = null ) {
</span></span></pre></div>
<a id="trunksrcwpincludesclasswpimageeditorimagickphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-includes/class-wp-image-editor-imagick.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/class-wp-image-editor-imagick.php 2020-08-15 20:54:46 UTC (rev 48797)
+++ trunk/src/wp-includes/class-wp-image-editor-imagick.php 2020-08-16 13:31:57 UTC (rev 48798)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -548,6 +548,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> } catch ( Exception $e ) {
</span><span class="cx" style="display: block; padding: 0 10px"> return new WP_Error( 'image_crop_error', $e->getMessage() );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
</ins><span class="cx" style="display: block; padding: 0 10px"> return $this->update_size();
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -582,6 +583,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> } catch ( Exception $e ) {
</span><span class="cx" style="display: block; padding: 0 10px"> return new WP_Error( 'image_rotate_error', $e->getMessage() );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
</ins><span class="cx" style="display: block; padding: 0 10px"> return true;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span></span></pre></div>
<a id="trunksrcwpincludesdeprecatedphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-includes/deprecated.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/deprecated.php 2020-08-15 20:54:46 UTC (rev 48797)
+++ trunk/src/wp-includes/deprecated.php 2020-08-16 13:31:57 UTC (rev 48798)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -3196,7 +3196,8 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * @see wp_get_image_editor()
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @param string $file Filename of the image to load.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @return resource The resulting image resource on success, Error string on failure.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @return resource|GdImage|string The resulting image resource or GdImage instance on success,
+ * error string on failure.
</ins><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> function wp_load_image( $file ) {
</span><span class="cx" style="display: block; padding: 0 10px"> _deprecated_function( __FUNCTION__, '3.5.0', 'wp_get_image_editor()' );
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -3217,7 +3218,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $image = imagecreatefromstring( file_get_contents( $file ) );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ( ! is_resource( $image ) ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( ! is_gd_image( $image ) ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> /* translators: %s: File name. */
</span><span class="cx" style="display: block; padding: 0 10px"> return sprintf( __( 'File “%s” is not an image.' ), $file );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span></span></pre></div>
<a id="trunksrcwpincludesmediaphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-includes/media.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/media.php 2020-08-15 20:54:46 UTC (rev 48797)
+++ trunk/src/wp-includes/media.php 2020-08-16 13:31:57 UTC (rev 48798)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -3459,15 +3459,19 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * @since 2.9.0
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @param int $width Image width in pixels.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @param int $height Image height in pixels..
- * @return resource The GD image resource.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @param int $height Image height in pixels.
+ * @return resource|GdImage The GD image resource or GdImage instance.
</ins><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> function wp_imagecreatetruecolor( $width, $height ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $img = imagecreatetruecolor( $width, $height );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ( is_resource( $img ) && function_exists( 'imagealphablending' ) && function_exists( 'imagesavealpha' ) ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+ if ( is_gd_image( $img )
+ && function_exists( 'imagealphablending' ) && function_exists( 'imagesavealpha' )
+ ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> imagealphablending( $img, false );
</span><span class="cx" style="display: block; padding: 0 10px"> imagesavealpha( $img, true );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
</ins><span class="cx" style="display: block; padding: 0 10px"> return $img;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span></span></pre></div>
<a id="trunktestsphpunittestsimagefunctionsphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/tests/phpunit/tests/image/functions.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/image/functions.php 2020-08-15 20:54:46 UTC (rev 48797)
+++ trunk/tests/phpunit/tests/image/functions.php 2020-08-16 13:31:57 UTC (rev 48798)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -123,7 +123,29 @@
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
</ins><span class="cx" style="display: block; padding: 0 10px"> /**
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @ticket 50833
+ */
+ function test_is_gd_image_invalid_types() {
+ $this->assertFalse( is_gd_image( new stdClass() ) );
+ $this->assertFalse( is_gd_image( array() ) );
+ $this->assertFalse( is_gd_image( null ) );
+
+ $handle = fopen( __FILE__, 'r' );
+ $this->assertFalse( is_gd_image( $handle ) );
+ fclose( $handle );
+ }
+
+ /**
+ * @ticket 50833
+ * @requires extension gd
+ */
+ function test_is_gd_image_valid_types() {
+ $this->assertTrue( is_gd_image( imagecreate( 5, 5 ) ) );
+ }
+
+ /**
</ins><span class="cx" style="display: block; padding: 0 10px"> * Test save image file and mime_types
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @ticket 6821
</span></span></pre>
</div>
</div>
</body>
</html>