Imsanity - Version 2.8.0

Version Description

  • added: support for resizing WebP images via ImageMagick
  • changed: update attachment file size to keep WP 6.0 metadata in sync
  • changed: use original image for resizing if full size version was scaled by WordPress
  • fixed: JS scroller during bulk resize causes unexpected behavior
Download this release

Release Info

Developer nosilver4u
Plugin Icon 128x128 Imsanity
Version 2.8.0
Comparing to
See all releases

Code changes from version 2.7.2 to 2.8.0

Files changed (7) hide show
  1. .travis.yml +1 -1
  2. changelog.txt +6 -0
  3. imsanity.php +6 -2
  4. libs/utils.php +38 -2
  5. readme.txt +10 -4
  6. scripts/imsanity.js +0 -3
  7. settings.php +2 -2
.travis.yml CHANGED
@@ -1,5 +1,5 @@
1
  os: linux
2
- dist: xenial
3
 
4
  language: php
5
 
1
  os: linux
2
+ dist: bionic
3
 
4
  language: php
5
 
changelog.txt CHANGED
@@ -1,3 +1,9 @@
 
 
 
 
 
 
1
  = 2.7.2 =
2
  * fixed: delete originals might remove full-size version in rare cases
3
  * fixed: error thrown for image that is 1 pixel larger than max dimensions
1
+ = 2.8.0 =
2
+ * added: support for resizing WebP images via ImageMagick
3
+ * changed: update attachment file size to keep WP 6.0 metadata in sync
4
+ * changed: use original image for resizing if full size version was scaled by WordPress
5
+ * fixed: JS scroller during bulk resize causes unexpected behavior
6
+
7
  = 2.7.2 =
8
  * fixed: delete originals might remove full-size version in rare cases
9
  * fixed: error thrown for image that is 1 pixel larger than max dimensions
imsanity.php CHANGED
@@ -14,7 +14,9 @@ Plugin URI: https://wordpress.org/plugins/imsanity/
14
  Description: Imsanity stops insanely huge image uploads
15
  Author: Exactly WWW
16
  Domain Path: /languages
17
- Version: 2.7.2
 
 
18
  Author URI: https://ewww.io/
19
  License: GPLv3
20
  */
@@ -23,7 +25,7 @@ if ( ! defined( 'ABSPATH' ) ) {
23
  exit;
24
  }
25
 
26
- define( 'IMSANITY_VERSION', '2.7.2' );
27
  define( 'IMSANITY_SCHEMA_VERSION', '1.1' );
28
 
29
  define( 'IMSANITY_DEFAULT_MAX_WIDTH', 1920 );
@@ -367,3 +369,5 @@ add_action( 'plugins_loaded', 'imsanity_init' );
367
  add_filter( 'manage_media_columns', 'imsanity_media_columns' );
368
  // Outputs the actual column information for each attachment.
369
  add_action( 'manage_media_custom_column', 'imsanity_custom_column', 10, 2 );
 
 
14
  Description: Imsanity stops insanely huge image uploads
15
  Author: Exactly WWW
16
  Domain Path: /languages
17
+ Version: 2.8.0
18
+ Requires at least: 5.5
19
+ Requires PHP: 7.2
20
  Author URI: https://ewww.io/
21
  License: GPLv3
22
  */
25
  exit;
26
  }
27
 
28
+ define( 'IMSANITY_VERSION', '2.8.0' );
29
  define( 'IMSANITY_SCHEMA_VERSION', '1.1' );
30
 
31
  define( 'IMSANITY_DEFAULT_MAX_WIDTH', 1920 );
369
  add_filter( 'manage_media_columns', 'imsanity_media_columns' );
370
  // Outputs the actual column information for each attachment.
371
  add_action( 'manage_media_custom_column', 'imsanity_custom_column', 10, 2 );
372
+ // Checks for WebP support and adds it to the allowed mime types.
373
+ add_filter( 'imsanity_allowed_mimes', 'imsanity_add_webp_support' );
libs/utils.php CHANGED
@@ -80,11 +80,32 @@ function imsanity_quick_mimetype( $path ) {
80
  return 'image/gif';
81
  case 'pdf':
82
  return 'application/pdf';
 
 
83
  default:
84
  return false;
85
  }
86
  }
87
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
88
  /**
89
  * Gets the orientation/rotation of a JPG image using the EXIF data.
90
  *
@@ -260,7 +281,12 @@ function imsanity_resize_from_id( $id = 0 ) {
260
  list( $neww, $newh ) = wp_constrain_dimensions( $oldw, $oldh, $maxw, $maxh );
261
  }
262
 
263
- $resizeresult = imsanity_image_resize( $oldpath, $neww, $newh, apply_filters( 'imsanity_crop_image', false ), null, null, $quality );
 
 
 
 
 
264
 
265
  if ( $resizeresult && ! is_wp_error( $resizeresult ) ) {
266
  $newpath = $resizeresult;
@@ -338,7 +364,12 @@ function imsanity_resize_from_id( $id = 0 ) {
338
  $update_meta = true;
339
  }
340
  if ( ! empty( $update_meta ) ) {
 
 
 
 
341
  wp_update_attachment_metadata( $id, $meta );
 
342
  }
343
  } else {
344
  $results = array(
@@ -432,13 +463,18 @@ function imsanity_remove_original_image( $id, $meta = null ) {
432
  */
433
  function imsanity_image_resize( $file, $max_w, $max_h, $crop = false, $suffix = null, $dest_path = null, $jpeg_quality = 82 ) {
434
  if ( function_exists( 'wp_get_image_editor' ) ) {
 
435
  $editor = wp_get_image_editor( $file );
436
  if ( is_wp_error( $editor ) ) {
437
  return $editor;
438
  }
439
- $editor->set_quality( min( 92, $jpeg_quality ) );
440
 
441
  $ftype = imsanity_quick_mimetype( $file );
 
 
 
 
 
442
 
443
  // Return 1 to override auto-rotate.
444
  $orientation = (int) apply_filters( 'imsanity_orientation', imsanity_get_orientation( $file, $ftype ) );
80
  return 'image/gif';
81
  case 'pdf':
82
  return 'application/pdf';
83
+ case 'webp':
84
+ return 'image/webp';
85
  default:
86
  return false;
87
  }
88
  }
89
 
90
+ /**
91
+ * Check for WebP support in the image editor and add to the list of allowed mimes.
92
+ *
93
+ * @param array $mimes A list of allowed mime types.
94
+ * @return array The updated list of mimes after checking WebP support.
95
+ */
96
+ function imsanity_add_webp_support( $mimes ) {
97
+ if ( ! in_array( 'image/webp', $mimes, true ) ) {
98
+ if ( class_exists( 'Imagick' ) ) {
99
+ $imagick = new Imagick();
100
+ $formats = $imagick->queryFormats();
101
+ if ( in_array( 'WEBP', $formats, true ) ) {
102
+ $mimes[] = 'image/webp';
103
+ }
104
+ }
105
+ }
106
+ return $mimes;
107
+ }
108
+
109
  /**
110
  * Gets the orientation/rotation of a JPG image using the EXIF data.
111
  *
281
  list( $neww, $newh ) = wp_constrain_dimensions( $oldw, $oldh, $maxw, $maxh );
282
  }
283
 
284
+ $source_image = $oldpath;
285
+ if ( ! empty( $meta['original_image'] ) ) {
286
+ $source_image = path_join( dirname( $oldpath ), $meta['original_image'] );
287
+ imsanity_debug( "subbing in $source_image for resizing" );
288
+ }
289
+ $resizeresult = imsanity_image_resize( $source_image, $neww, $newh, apply_filters( 'imsanity_crop_image', false ), null, null, $quality );
290
 
291
  if ( $resizeresult && ! is_wp_error( $resizeresult ) ) {
292
  $newpath = $resizeresult;
364
  $update_meta = true;
365
  }
366
  if ( ! empty( $update_meta ) ) {
367
+ clearstatcache();
368
+ if ( ! empty( $oldpath ) && is_file( $oldpath ) ) {
369
+ $meta['filesize'] = filesize( $oldpath );
370
+ }
371
  wp_update_attachment_metadata( $id, $meta );
372
+ do_action( 'imsanity_post_process_attachment', $id, $meta );
373
  }
374
  } else {
375
  $results = array(
463
  */
464
  function imsanity_image_resize( $file, $max_w, $max_h, $crop = false, $suffix = null, $dest_path = null, $jpeg_quality = 82 ) {
465
  if ( function_exists( 'wp_get_image_editor' ) ) {
466
+ imsanity_debug( "resizing $file" );
467
  $editor = wp_get_image_editor( $file );
468
  if ( is_wp_error( $editor ) ) {
469
  return $editor;
470
  }
 
471
 
472
  $ftype = imsanity_quick_mimetype( $file );
473
+ if ( 'image/webp' === $ftype ) {
474
+ $jpeg_quality = (int) round( $jpeg_quality * .91 );
475
+ }
476
+
477
+ $editor->set_quality( min( 92, $jpeg_quality ) );
478
 
479
  // Return 1 to override auto-rotate.
480
  $orientation = (int) apply_filters( 'imsanity_orientation', imsanity_get_orientation( $file, $ftype ) );
readme.txt CHANGED
@@ -2,10 +2,10 @@
2
  Contributors: nosilver4u
3
  Donate link: https://ewww.io/donate/
4
  Tags: image, scale, resize, space saver, quality, upload
5
- Requires at least: 5.1
6
- Tested up to: 5.7
7
- Requires PHP: 5.6
8
- Stable tag: 2.7.2
9
  License: GPLv3
10
 
11
  Imsanity automatically resizes huge image uploads. Are contributors uploading huge photos? Tired of manually resizing your images? Imsanity to the rescue!
@@ -106,6 +106,12 @@ Questions may be posted on the support forum at https://wordpress.org/support/pl
106
 
107
  == Changelog ==
108
 
 
 
 
 
 
 
109
  = 2.7.2 =
110
  * fixed: delete originals might remove full-size version in rare cases
111
  * fixed: error thrown for image that is 1 pixel larger than max dimensions
2
  Contributors: nosilver4u
3
  Donate link: https://ewww.io/donate/
4
  Tags: image, scale, resize, space saver, quality, upload
5
+ Requires at least: 5.5
6
+ Tested up to: 6.0
7
+ Requires PHP: 7.2
8
+ Stable tag: 2.8.0
9
  License: GPLv3
10
 
11
  Imsanity automatically resizes huge image uploads. Are contributors uploading huge photos? Tired of manually resizing your images? Imsanity to the rescue!
106
 
107
  == Changelog ==
108
 
109
+ = 2.8.0 =
110
+ * added: support for resizing WebP images via ImageMagick
111
+ * changed: update attachment file size to keep WP 6.0 metadata in sync
112
+ * changed: use original image for resizing if full size version was scaled by WordPress
113
+ * fixed: JS scroller during bulk resize causes unexpected behavior
114
+
115
  = 2.7.2 =
116
  * fixed: delete originals might remove full-size version in rare cases
117
  * fixed: error thrown for image that is 1 pixel larger than max dimensions
scripts/imsanity.js CHANGED
@@ -101,8 +101,6 @@ function imsanity_resize_next(next_index) {
101
  console.warn('Invalid JSON Response: ' + response);
102
  }
103
  }
104
-
105
- target.animate({scrollTop: target.prop('scrollHeight')}, 200);
106
  // recurse
107
  imsanity_resize_next(next_index+1);
108
  }
@@ -122,7 +120,6 @@ function imsanity_resize_complete() {
122
  {_wpnonce: imsanity_vars._wpnonce, action: 'imsanity_bulk_complete'}
123
  );
124
  }
125
- target.animate({scrollTop: target.prop('scrollHeight')});
126
  }
127
 
128
  /**
101
  console.warn('Invalid JSON Response: ' + response);
102
  }
103
  }
 
 
104
  // recurse
105
  imsanity_resize_next(next_index+1);
106
  }
120
  {_wpnonce: imsanity_vars._wpnonce, action: 'imsanity_bulk_complete'}
121
  );
122
  }
 
123
  }
124
 
125
  /**
settings.php CHANGED
@@ -311,7 +311,7 @@ function imsanity_network_settings() {
311
  </th>
312
  <td>
313
  <input type='text' id='imsanity_quality' name='imsanity_quality' class='small-text' value='<?php echo (int) $settings->imsanity_quality; ?>' />
314
- <?php esc_html_e( 'Valid values are 1-100.', 'imsanity' ); ?>
315
  <p class='description'><?php esc_html_e( 'Only used when resizing images, does not affect thumbnails.', 'imsanity' ); ?></p>
316
  </td>
317
  </tr>
@@ -791,7 +791,7 @@ function imsanity_settings_page_form() {
791
  </th>
792
  <td>
793
  <input type='text' id='imsanity_quality' name='imsanity_quality' class='small-text' value='<?php echo imsanity_jpg_quality(); ?>' />
794
- <?php esc_html_e( 'Valid values are 1-100.', 'imsanity' ); ?>
795
  <p class='description'><?php esc_html_e( 'Only used when resizing images, does not affect thumbnails.', 'imsanity' ); ?></p>
796
  </td>
797
  </tr>
311
  </th>
312
  <td>
313
  <input type='text' id='imsanity_quality' name='imsanity_quality' class='small-text' value='<?php echo (int) $settings->imsanity_quality; ?>' />
314
+ <?php esc_html_e( 'Usable values are 1-92.', 'imsanity' ); ?>
315
  <p class='description'><?php esc_html_e( 'Only used when resizing images, does not affect thumbnails.', 'imsanity' ); ?></p>
316
  </td>
317
  </tr>
791
  </th>
792
  <td>
793
  <input type='text' id='imsanity_quality' name='imsanity_quality' class='small-text' value='<?php echo imsanity_jpg_quality(); ?>' />
794
+ <?php esc_html_e( 'Usable values are 1-92.', 'imsanity' ); ?>
795
  <p class='description'><?php esc_html_e( 'Only used when resizing images, does not affect thumbnails.', 'imsanity' ); ?></p>
796
  </td>
797
  </tr>