Version Description
- fixed: delete originals might remove full-size version in rare cases
- fixed: error thrown for image that is 1 pixel larger than max dimensions
Download this release
Release Info
Developer | nosilver4u |
Plugin | Imsanity |
Version | 2.7.2 |
Comparing to | |
See all releases |
Code changes from version 2.7.0 to 2.7.2
- changelog.txt +8 -0
- imsanity.php +6 -7
- libs/utils.php +37 -9
- media.php +13 -10
- readme.txt +11 -3
- scripts/imsanity.js +5 -1
- settings.php +4 -2
changelog.txt
CHANGED
@@ -1,3 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
= 2.7.0 =
|
2 |
* changed: bulk resizer will resize all images with no limits, use list mode for selective resizing
|
3 |
* added: see current dimensions and resize individual images in Media Library list mode
|
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
|
4 |
+
|
5 |
+
= 2.7.1 =
|
6 |
+
* changed: clarify text for queue reset button
|
7 |
+
* changed: Delete Originals function in bulk/selective resizer will clean metadata if original image is already gone
|
8 |
+
|
9 |
= 2.7.0 =
|
10 |
* changed: bulk resizer will resize all images with no limits, use list mode for selective resizing
|
11 |
* added: see current dimensions and resize individual images in Media Library list mode
|
imsanity.php
CHANGED
@@ -13,9 +13,8 @@ Plugin Name: Imsanity
|
|
13 |
Plugin URI: https://wordpress.org/plugins/imsanity/
|
14 |
Description: Imsanity stops insanely huge image uploads
|
15 |
Author: Exactly WWW
|
16 |
-
Text Domain: imsanity
|
17 |
Domain Path: /languages
|
18 |
-
Version: 2.7.
|
19 |
Author URI: https://ewww.io/
|
20 |
License: GPLv3
|
21 |
*/
|
@@ -24,7 +23,7 @@ if ( ! defined( 'ABSPATH' ) ) {
|
|
24 |
exit;
|
25 |
}
|
26 |
|
27 |
-
define( 'IMSANITY_VERSION', '2.7.
|
28 |
define( 'IMSANITY_SCHEMA_VERSION', '1.1' );
|
29 |
|
30 |
define( 'IMSANITY_DEFAULT_MAX_WIDTH', 1920 );
|
@@ -226,7 +225,7 @@ function imsanity_handle_upload( $params ) {
|
|
226 |
|
227 |
list( $oldw, $oldh ) = getimagesize( $oldpath );
|
228 |
|
229 |
-
if ( ( $oldw > $maxw && $maxw > 0 ) || ( $oldh > $maxh && $maxh > 0 ) ) {
|
230 |
$quality = imsanity_get_option( 'imsanity_quality', IMSANITY_DEFAULT_QUALITY );
|
231 |
|
232 |
$ftype = imsanity_quick_mimetype( $oldpath );
|
@@ -258,12 +257,12 @@ function imsanity_handle_upload( $params ) {
|
|
258 |
$newpath = $resizeresult;
|
259 |
|
260 |
if ( is_file( $newpath ) && filesize( $newpath ) < filesize( $oldpath ) ) {
|
261 |
-
//
|
262 |
unlink( $oldpath );
|
263 |
rename( $newpath, $oldpath );
|
264 |
} elseif ( is_file( $newpath ) ) {
|
265 |
-
//
|
266 |
-
//
|
267 |
unlink( $newpath );
|
268 |
}
|
269 |
} elseif ( false === $resizeresult ) {
|
13 |
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 |
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 );
|
225 |
|
226 |
list( $oldw, $oldh ) = getimagesize( $oldpath );
|
227 |
|
228 |
+
if ( ( $oldw > $maxw + 1 && $maxw > 0 ) || ( $oldh > $maxh + 1 && $maxh > 0 ) ) {
|
229 |
$quality = imsanity_get_option( 'imsanity_quality', IMSANITY_DEFAULT_QUALITY );
|
230 |
|
231 |
$ftype = imsanity_quick_mimetype( $oldpath );
|
257 |
$newpath = $resizeresult;
|
258 |
|
259 |
if ( is_file( $newpath ) && filesize( $newpath ) < filesize( $oldpath ) ) {
|
260 |
+
// We saved some file space. remove original and replace with resized image.
|
261 |
unlink( $oldpath );
|
262 |
rename( $newpath, $oldpath );
|
263 |
} elseif ( is_file( $newpath ) ) {
|
264 |
+
// The resized image is actually bigger in filesize (most likely due to jpg quality).
|
265 |
+
// Keep the old one and just get rid of the resized image.
|
266 |
unlink( $newpath );
|
267 |
}
|
268 |
} elseif ( false === $resizeresult ) {
|
libs/utils.php
CHANGED
@@ -355,12 +355,41 @@ function imsanity_resize_from_id( $id = 0 ) {
|
|
355 |
return $results;
|
356 |
}
|
357 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
358 |
/**
|
359 |
* Remove the backed-up original_image stored by WP 5.3+.
|
360 |
*
|
361 |
* @param int $id The attachment ID number.
|
362 |
* @param array $meta The attachment metadata. Optional, default to null.
|
363 |
-
* @return bool
|
364 |
*/
|
365 |
function imsanity_remove_original_image( $id, $meta = null ) {
|
366 |
$id = (int) $id;
|
@@ -376,15 +405,14 @@ function imsanity_remove_original_image( $id, $meta = null ) {
|
|
376 |
imsanity_get_option( 'imsanity_delete_originals', false ) &&
|
377 |
! empty( $meta['original_image'] ) && function_exists( 'wp_get_original_image_path' )
|
378 |
) {
|
379 |
-
$original_image =
|
380 |
-
if (
|
381 |
-
|
382 |
}
|
383 |
-
|
384 |
-
|
385 |
-
|
386 |
-
|
387 |
-
}
|
388 |
}
|
389 |
}
|
390 |
return false;
|
355 |
return $results;
|
356 |
}
|
357 |
|
358 |
+
/**
|
359 |
+
* Find the path to a backed-up original (not the full-size version like the core WP function).
|
360 |
+
*
|
361 |
+
* @param int $id The attachment ID number.
|
362 |
+
* @param string $image_file The path to a scaled image file.
|
363 |
+
* @param array $meta The attachment metadata. Optional, default to null.
|
364 |
+
* @return bool True on success, false on failure.
|
365 |
+
*/
|
366 |
+
function imsanity_get_original_image_path( $id, $image_file = '', $meta = null ) {
|
367 |
+
$id = (int) $id;
|
368 |
+
if ( empty( $id ) ) {
|
369 |
+
return false;
|
370 |
+
}
|
371 |
+
if ( ! wp_attachment_is_image( $id ) ) {
|
372 |
+
return false;
|
373 |
+
}
|
374 |
+
if ( is_null( $meta ) ) {
|
375 |
+
$meta = wp_get_attachment_metadata( $id );
|
376 |
+
}
|
377 |
+
if ( empty( $image_file ) ) {
|
378 |
+
$image_file = get_attached_file( $id, true );
|
379 |
+
}
|
380 |
+
if ( empty( $image_file ) || ! is_iterable( $meta ) || empty( $meta['original_image'] ) ) {
|
381 |
+
return false;
|
382 |
+
}
|
383 |
+
|
384 |
+
return trailingslashit( dirname( $image_file ) ) . wp_basename( $meta['original_image'] );
|
385 |
+
}
|
386 |
+
|
387 |
/**
|
388 |
* Remove the backed-up original_image stored by WP 5.3+.
|
389 |
*
|
390 |
* @param int $id The attachment ID number.
|
391 |
* @param array $meta The attachment metadata. Optional, default to null.
|
392 |
+
* @return bool|array Returns meta if modified, false otherwise (even if an "unlinked" original is removed).
|
393 |
*/
|
394 |
function imsanity_remove_original_image( $id, $meta = null ) {
|
395 |
$id = (int) $id;
|
405 |
imsanity_get_option( 'imsanity_delete_originals', false ) &&
|
406 |
! empty( $meta['original_image'] ) && function_exists( 'wp_get_original_image_path' )
|
407 |
) {
|
408 |
+
$original_image = imsanity_get_original_image_path( $id, '', $meta );
|
409 |
+
if ( $original_image && is_file( $original_image ) && is_writable( $original_image ) ) {
|
410 |
+
unlink( $original_image );
|
411 |
}
|
412 |
+
clearstatcache();
|
413 |
+
if ( empty( $original_image ) || ! is_file( $original_image ) ) {
|
414 |
+
unset( $meta['original_image'] );
|
415 |
+
return $meta;
|
|
|
416 |
}
|
417 |
}
|
418 |
return false;
|
media.php
CHANGED
@@ -72,13 +72,13 @@ function imsanity_custom_column( $column_name, $id, $meta = null ) {
|
|
72 |
return;
|
73 |
}
|
74 |
// Let folks filter the allowed mime-types for resizing.
|
75 |
-
$allowed_types = apply_filters( 'imsanity_allowed_mimes', array( 'image/png', 'image/gif', 'image/jpeg' ), $
|
76 |
if ( is_string( $allowed_types ) ) {
|
77 |
$allowed_types = array( $allowed_types );
|
78 |
} elseif ( ! is_array( $allowed_types ) ) {
|
79 |
$allowed_types = array();
|
80 |
}
|
81 |
-
$ftype = imsanity_quick_mimetype( $
|
82 |
if ( ! in_array( $ftype, $allowed_types, true ) ) {
|
83 |
echo '</div>';
|
84 |
return;
|
@@ -115,15 +115,18 @@ function imsanity_custom_column( $column_name, $id, $meta = null ) {
|
|
115 |
$original_image = wp_get_original_image_path( $id, true );
|
116 |
}
|
117 |
if ( ! empty( $original_image ) && is_file( $original_image ) && is_writable( $original_image ) ) {
|
118 |
-
$
|
119 |
-
|
120 |
-
|
121 |
-
'<div><button class="imsanity-manual-remove-original button button-secondary" data-id="%1$d" data-nonce="%2$s">%3$s</button>',
|
122 |
-
$id,
|
123 |
-
esc_attr( $manual_nonce ),
|
124 |
-
esc_html__( 'Remove Original', 'imsanity' )
|
125 |
-
);
|
126 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
127 |
}
|
128 |
echo '</div>';
|
129 |
}
|
72 |
return;
|
73 |
}
|
74 |
// Let folks filter the allowed mime-types for resizing.
|
75 |
+
$allowed_types = apply_filters( 'imsanity_allowed_mimes', array( 'image/png', 'image/gif', 'image/jpeg' ), $file_path );
|
76 |
if ( is_string( $allowed_types ) ) {
|
77 |
$allowed_types = array( $allowed_types );
|
78 |
} elseif ( ! is_array( $allowed_types ) ) {
|
79 |
$allowed_types = array();
|
80 |
}
|
81 |
+
$ftype = imsanity_quick_mimetype( $file_path );
|
82 |
if ( ! in_array( $ftype, $allowed_types, true ) ) {
|
83 |
echo '</div>';
|
84 |
return;
|
115 |
$original_image = wp_get_original_image_path( $id, true );
|
116 |
}
|
117 |
if ( ! empty( $original_image ) && is_file( $original_image ) && is_writable( $original_image ) ) {
|
118 |
+
$link_text = __( 'Remove Original', 'imsanity' );
|
119 |
+
} else {
|
120 |
+
$link_text = __( 'Remove Original Link', 'imsanity' );
|
|
|
|
|
|
|
|
|
|
|
121 |
}
|
122 |
+
$manual_nonce = wp_create_nonce( 'imsanity-manual-resize' );
|
123 |
+
// Give the user the option to optimize the image right now.
|
124 |
+
printf(
|
125 |
+
'<div><button class="imsanity-manual-remove-original button button-secondary" data-id="%1$d" data-nonce="%2$s">%3$s</button>',
|
126 |
+
$id,
|
127 |
+
esc_attr( $manual_nonce ),
|
128 |
+
esc_html( $link_text )
|
129 |
+
);
|
130 |
}
|
131 |
echo '</div>';
|
132 |
}
|
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.
|
6 |
-
Tested up to: 5.
|
7 |
Requires PHP: 5.6
|
8 |
-
Stable tag: 2.7.
|
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,14 @@ Questions may be posted on the support forum at https://wordpress.org/support/pl
|
|
106 |
|
107 |
== Changelog ==
|
108 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
109 |
= 2.7.0 =
|
110 |
* changed: bulk resizer will resize all images with no limits, use list mode for selective resizing
|
111 |
* added: see current dimensions and resize individual images in Media Library list mode
|
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 |
|
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
|
112 |
+
|
113 |
+
= 2.7.1 =
|
114 |
+
* changed: clarify text for queue reset button
|
115 |
+
* changed: Delete Originals function in bulk/selective resizer will clean metadata if original image is already gone
|
116 |
+
|
117 |
= 2.7.0 =
|
118 |
* changed: bulk resizer will resize all images with no limits, use list mode for selective resizing
|
119 |
* added: see current dimensions and resize individual images in Media Library list mode
|
scripts/imsanity.js
CHANGED
@@ -130,6 +130,10 @@ function imsanity_resize_complete() {
|
|
130 |
* @param string the id of the html element into which results will be appended
|
131 |
*/
|
132 |
function imsanity_load_images() {
|
|
|
|
|
|
|
|
|
133 |
jQuery('#imsanity-examine-button').hide();
|
134 |
jQuery('.imsanity-bulk-text').hide();
|
135 |
jQuery('#imsanity-bulk-reset').hide();
|
@@ -141,7 +145,7 @@ function imsanity_load_images() {
|
|
141 |
function(response) {
|
142 |
var is_json = true;
|
143 |
try {
|
144 |
-
var images =
|
145 |
} catch ( err ) {
|
146 |
is_json = false;
|
147 |
}
|
130 |
* @param string the id of the html element into which results will be appended
|
131 |
*/
|
132 |
function imsanity_load_images() {
|
133 |
+
var imsanity_really_resize_all = confirm(imsanity_vars.resize_all_prompt);
|
134 |
+
if ( ! imsanity_really_resize_all ) {
|
135 |
+
return;
|
136 |
+
}
|
137 |
jQuery('#imsanity-examine-button').hide();
|
138 |
jQuery('.imsanity-bulk-text').hide();
|
139 |
jQuery('#imsanity-bulk-reset').hide();
|
145 |
function(response) {
|
146 |
var is_json = true;
|
147 |
try {
|
148 |
+
var images = JSON.parse(response);
|
149 |
} catch ( err ) {
|
150 |
is_json = false;
|
151 |
}
|
settings.php
CHANGED
@@ -103,6 +103,7 @@ function imsanity_queue_script( $hook ) {
|
|
103 |
'imsanity_vars',
|
104 |
array(
|
105 |
'_wpnonce' => wp_create_nonce( 'imsanity-bulk' ),
|
|
|
106 |
'resizing_complete' => esc_html__( 'Resizing Complete', 'imsanity' ) . ' - <a target="_blank" href="https://wordpress.org/support/plugin/imsanity/reviews/#new-post">' . esc_html__( 'Leave a Review', 'imsanity' ) . '</a>',
|
107 |
'resize_selected' => esc_html__( 'Resize Selected Images', 'imsanity' ),
|
108 |
'resizing' => '<p>' . esc_html__( 'Please wait...', 'imsanity' ) . " <img src='$loading_image' /></p>",
|
@@ -704,14 +705,15 @@ function imsanity_settings_page() {
|
|
704 |
<button class="button-primary" onclick="imsanity_load_images();"><?php echo esc_html( $button_text ); ?></button>
|
705 |
</p>
|
706 |
<form id="imsanity-bulk-stop" style="display:none;margin:1em 0 1em;" method="post" action="">
|
707 |
-
<button type="submit" class="button-secondary action"><?php esc_html_e( 'Stop Resizing', 'imsanity' ); ?></button>
|
|
|
708 |
</form>
|
709 |
<?php if ( get_option( 'imsanity_resume_id' ) ) : ?>
|
710 |
<p class="imsanity-bulk-text" style="margin-top:1em;"><?php esc_html_e( 'Would you like to start back at the beginning?', 'imsanity' ); ?></p>
|
711 |
<form class="imsanity-bulk-form" method="post" action="">
|
712 |
<?php wp_nonce_field( 'imsanity-bulk-reset', 'imsanity_wpnonce' ); ?>
|
713 |
<input type="hidden" name="imsanity_reset" value="1">
|
714 |
-
<button id="imsanity-bulk-reset" type="submit" class="button-secondary action"><?php esc_html_e( '
|
715 |
</form>
|
716 |
<?php endif; ?>
|
717 |
<div id="imsanity_loading" style="display: none;margin:1em 0 1em;"><img src="<?php echo plugins_url( 'images/ajax-loader.gif', __FILE__ ); ?>" style="margin-bottom: .25em; vertical-align:middle;" />
|
103 |
'imsanity_vars',
|
104 |
array(
|
105 |
'_wpnonce' => wp_create_nonce( 'imsanity-bulk' ),
|
106 |
+
'resize_all_prompt' => esc_html__( 'You are about to resize all your existing images. Please be sure your site is backed up before proceeding. Do you wish to continue?', 'imsanity' ),
|
107 |
'resizing_complete' => esc_html__( 'Resizing Complete', 'imsanity' ) . ' - <a target="_blank" href="https://wordpress.org/support/plugin/imsanity/reviews/#new-post">' . esc_html__( 'Leave a Review', 'imsanity' ) . '</a>',
|
108 |
'resize_selected' => esc_html__( 'Resize Selected Images', 'imsanity' ),
|
109 |
'resizing' => '<p>' . esc_html__( 'Please wait...', 'imsanity' ) . " <img src='$loading_image' /></p>",
|
705 |
<button class="button-primary" onclick="imsanity_load_images();"><?php echo esc_html( $button_text ); ?></button>
|
706 |
</p>
|
707 |
<form id="imsanity-bulk-stop" style="display:none;margin:1em 0 1em;" method="post" action="">
|
708 |
+
<button type="submit" class="button-secondary action"><?php esc_html_e( 'Stop Resizing', 'imsanity' ); ?></button><br>
|
709 |
+
*<i><?php esc_html_e( 'You will be able to resume the process later.', 'imsanity' ); ?></i>
|
710 |
</form>
|
711 |
<?php if ( get_option( 'imsanity_resume_id' ) ) : ?>
|
712 |
<p class="imsanity-bulk-text" style="margin-top:1em;"><?php esc_html_e( 'Would you like to start back at the beginning?', 'imsanity' ); ?></p>
|
713 |
<form class="imsanity-bulk-form" method="post" action="">
|
714 |
<?php wp_nonce_field( 'imsanity-bulk-reset', 'imsanity_wpnonce' ); ?>
|
715 |
<input type="hidden" name="imsanity_reset" value="1">
|
716 |
+
<button id="imsanity-bulk-reset" type="submit" class="button-secondary action"><?php esc_html_e( 'Clear Queue', 'imsanity' ); ?></button>
|
717 |
</form>
|
718 |
<?php endif; ?>
|
719 |
<div id="imsanity_loading" style="display: none;margin:1em 0 1em;"><img src="<?php echo plugins_url( 'images/ajax-loader.gif', __FILE__ ); ?>" style="margin-bottom: .25em; vertical-align:middle;" />
|