Ticket #40370: 40370-refresh-6-4-descriptions.patch
File 40370-refresh-6-4-descriptions.patch, 7.8 KB (added by , 12 months ago) |
---|
-
src/wp-includes/class-wp-image-editor-gd.php
From 60c81777e5d6fed5d8da312cd9d425654137c9cd Mon Sep 17 00:00:00 2001 From: Pea <pea@misfist.com> Date: Wed, 20 Sep 2023 19:33:14 -0400 Subject: [PATCH] Patch successfully applied patching file src/wp-includes/class-wp-image-editor-gd.php patching file src/wp-includes/class-wp-image-editor-imagick.php patching file src/wp-includes/class-wp-image-editor.php patching file tests/phpunit/tests/media.php Hunk #1 succeeded at 1362 (offset -1 lines). Update descriptions Update WP version 5.1.0 >6.4.0 Auto-fix code formatting --- src/wp-includes/class-wp-image-editor-gd.php | 26 +++++++++ .../class-wp-image-editor-imagick.php | 26 +++++++++ src/wp-includes/class-wp-image-editor.php | 34 ++++++++++- tests/phpunit/tests/media.php | 58 +++++++++++++++++++ 4 files changed, 143 insertions(+), 1 deletion(-) diff --git a/src/wp-includes/class-wp-image-editor-gd.php b/src/wp-includes/class-wp-image-editor-gd.php index de079357fb..7045aa1963 100644
a b class WP_Image_Editor_GD extends WP_Image_Editor { 153 153 return parent::update_size( $width, $height ); 154 154 } 155 155 156 /** 157 * Generates an hash for the current image. 158 * 159 * Concatenates crop coordinates, destination width and destination 160 * height into a string, calculates an MD5 hash, and returns first 8 characters. 161 * 162 * @since 6.4.0 163 * 164 * @param bool|array $crop Boolean or array with crop coordinates (e.g., array( x, y )). 165 * @param int $dst_w The destination width. 166 * @param int $dst_h The destination height. 167 * @return false|string 8-char MD5 hash. False for non-array $crop. 168 */ 169 protected function create_crop_hash( $crop, $dst_w, $dst_h ) { 170 if ( ! is_array( $crop ) ) { 171 return false; 172 } 173 174 $str = $crop[0] . $crop[1] . $dst_w . $dst_h; 175 $hash = substr( md5( $str ), 0, 8 ); 176 177 return parent::update_crop_hash( $hash ); 178 } 179 156 180 /** 157 181 * Resizes current image. 158 182 * … … class WP_Image_Editor_GD extends WP_Image_Editor { 220 244 imagecopyresampled( $resized, $this->image, $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h ); 221 245 222 246 if ( is_gd_image( $resized ) ) { 247 $this->create_crop_hash( $crop, $dst_w, $dst_h ); 223 248 $this->update_size( $dst_w, $dst_h ); 224 249 return $resized; 225 250 } … … class WP_Image_Editor_GD extends WP_Image_Editor { 534 559 'file' => wp_basename( apply_filters( 'image_make_intermediate_size', $filename ) ), 535 560 'width' => $this->size['width'], 536 561 'height' => $this->size['height'], 562 'hash' => $this->hash, 537 563 'mime-type' => $mime_type, 538 564 'filesize' => wp_filesize( $filename ), 539 565 ); -
src/wp-includes/class-wp-image-editor-imagick.php
diff --git a/src/wp-includes/class-wp-image-editor-imagick.php b/src/wp-includes/class-wp-image-editor-imagick.php index 03fe0bca69..3a6a3067bf 100644
a b class WP_Image_Editor_Imagick extends WP_Image_Editor { 309 309 } 310 310 } 311 311 312 /** 313 * Generates an hash for the current image. 314 * 315 * Concatenates crop coordinates, destination width and destination 316 * height into a string, calculates an MD5 hash, and returns first 8 characters. 317 * 318 * @since 6.4.0 319 * 320 * @param bool|array $crop Boolean or array with crop coordinates (e.g., array( x, y )). 321 * @param int $dst_w The destination width. 322 * @param int $dst_h The destination height. 323 * @return false|string 8-char MD5 hash. False for non-array $crop. 324 */ 325 protected function create_crop_hash( $crop, $dst_w, $dst_h ) { 326 if ( ! is_array( $crop ) ) { 327 return false; 328 } 329 330 $str = $crop[0] . $crop[1] . $dst_w . $dst_h; 331 $hash = substr( md5( $str ), 0, 8 ); 332 333 return parent::update_crop_hash( $hash ); 334 } 335 312 336 /** 313 337 * Resizes current image. 314 338 * … … class WP_Image_Editor_Imagick extends WP_Image_Editor { 343 367 list( $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h ) = $dims; 344 368 345 369 if ( $crop ) { 370 $this->create_crop_hash( $crop, $dst_w, $dst_h ); 346 371 return $this->crop( $src_x, $src_y, $src_w, $src_h, $dst_w, $dst_h ); 347 372 } 348 373 … … class WP_Image_Editor_Imagick extends WP_Image_Editor { 837 862 'file' => wp_basename( apply_filters( 'image_make_intermediate_size', $filename ) ), 838 863 'width' => $this->size['width'], 839 864 'height' => $this->size['height'], 865 'hash' => $this->hash, 840 866 'mime-type' => $mime_type, 841 867 'filesize' => wp_filesize( $filename ), 842 868 ); -
src/wp-includes/class-wp-image-editor.php
diff --git a/src/wp-includes/class-wp-image-editor.php b/src/wp-includes/class-wp-image-editor.php index 3c636dc6ba..da3bb14312 100644
a b 15 15 abstract class WP_Image_Editor { 16 16 protected $file = null; 17 17 protected $size = null; 18 protected $hash = null; 18 19 protected $mime_type = null; 19 20 protected $output_mime_type = null; 20 21 protected $default_mime_type = 'image/jpeg'; … … abstract class WP_Image_Editor { 221 222 return true; 222 223 } 223 224 225 226 /** 227 * Gets hash for the current image. 228 * 229 * @since 6.4.0 230 * 231 * @return string $hash 8-character MD5 hash. 232 */ 233 public function get_crop_hash() { 234 return $this->hash; 235 } 236 237 /** 238 * Sets hash for the current image. 239 * 240 * @since 6.4.0 241 * 242 * @param string $hash 8-character MD5 hash. 243 * @return true 244 */ 245 protected function update_crop_hash( $hash = null ) { 246 $this->hash = $hash; 247 return true; 248 } 249 224 250 /** 225 251 * Gets the Image Compression quality on a 1-100% scale. 226 252 * … … abstract class WP_Image_Editor { 486 512 return false; 487 513 } 488 514 489 return "{$this->size['width']}x{$this->size['height']}"; 515 $suffix = "{$this->size['width']}x{$this->size['height']}"; 516 517 if( $this->get_crop_hash() ){ 518 $suffix = $suffix . "-{$this->hash}"; 519 } 520 521 return $suffix; 490 522 } 491 523 492 524 /** -
tests/phpunit/tests/media.php
diff --git a/tests/phpunit/tests/media.php b/tests/phpunit/tests/media.php index 1ef1b93d4e..92fb182146 100644
a b VIDEO; 1362 1362 $this->assertSame( 'This is a test', $post->post_title ); 1363 1363 } 1364 1364 1365 /** 1366 * @ticket 40370 1367 */ 1368 public function test_media_handle_upload_add_image_size() { 1369 global $_wp_additional_image_sizes; 1370 1371 $iptc_file = DIR_TESTDATA . '/images/test-image-iptc.jpg'; 1372 1373 // Make a copy of this file as it gets moved during the file upload 1374 $tmp_name = wp_tempnam( $iptc_file ); 1375 1376 copy( $iptc_file, $tmp_name ); 1377 1378 // FIXME : change to correct upload method that creates thumbnails 1379 // and resuts in the new filenames with hashes 1380 $_FILES['async-upload'] = array( 1381 'tmp_name' => $tmp_name, 1382 'name' => 'test-image-iptc.jpg', 1383 'type' => 'image/jpeg', 1384 'error' => 0, 1385 'size' => filesize( $iptc_file ), 1386 ); 1387 1388 // add multiple image sizes 1389 add_image_size( 'newscentered', 400, 400, array( 'center', 'center') ); 1390 add_image_size( 'newstop', 400, 400, array( 'center', 'top' ) ); 1391 add_image_size( 'newsbottom', 400, 400, array( 'center', 'bottom' ) ); 1392 1393 $info = wp_upload_dir(); 1394 1395 $orig = array_map('basename', glob( ABSPATH . 'wp-content/uploads' 1396 . $info['subdir'] .'/*.png')); 1397 1398 // upload file 1399 $post_id = media_handle_upload( 1400 'async-upload', 1401 0, 1402 array(), 1403 array( 1404 'action' => 'test_iptc_upload', 1405 'test_form' => false, 1406 ) 1407 ); 1408 1409 unset( $_FILES['upload'] ); 1410 1411 // Clean up. 1412 wp_delete_attachment( $post_id ); 1413 1414 // 3 new files should be created 1415 $new = array_map('basename', glob( ABSPATH . 'wp-content/uploads' 1416 . $info['subdir'] .'/*.{jpg, png}', GLOB_BRACE)); 1417 $new_files = array_diff($new, $orig); 1418 1419 $this->assertCount(3, $new_files ); 1420 1421 } 1422 1365 1423 /** 1366 1424 * @ticket 33016 1367 1425 */