Version Description
- Improvement
- Resize images bigger than the maximum width defined in the settings using WP Image Editor instead of Imagify API
Download this release
Release Info
Developer | wp_media |
Plugin | Imagify Image Optimizer |
Version | 1.5.7 |
Comparing to | |
See all releases |
Code changes from version 1.5.6 to 1.5.7
imagify.php
CHANGED
@@ -3,7 +3,7 @@
|
|
3 |
Plugin Name: Imagify
|
4 |
Plugin URI: https://wordpress.org/plugins/imagify/
|
5 |
Description: Dramaticaly reduce image file sizes without losing quality, make your website load faster, boost your SEO and save money on your bandwith using Imagify, the new most advanced image optimization tool.
|
6 |
-
Version: 1.5.
|
7 |
Author: WP Media
|
8 |
Author URI: http://wp-media.me
|
9 |
Licence: GPLv2
|
@@ -17,7 +17,7 @@ Copyright 2016 WP Media
|
|
17 |
defined( 'ABSPATH' ) or die( 'Cheatin\' uh?' );
|
18 |
|
19 |
// Imagify defines
|
20 |
-
define( 'IMAGIFY_VERSION' , '1.5.
|
21 |
define( 'IMAGIFY_SLUG' , 'imagify' );
|
22 |
define( 'IMAGIFY_SETTINGS_SLUG' , IMAGIFY_SLUG . '_settings' );
|
23 |
define( 'IMAGIFY_WEB_MAIN' , 'https://imagify.io' );
|
3 |
Plugin Name: Imagify
|
4 |
Plugin URI: https://wordpress.org/plugins/imagify/
|
5 |
Description: Dramaticaly reduce image file sizes without losing quality, make your website load faster, boost your SEO and save money on your bandwith using Imagify, the new most advanced image optimization tool.
|
6 |
+
Version: 1.5.7
|
7 |
Author: WP Media
|
8 |
Author URI: http://wp-media.me
|
9 |
Licence: GPLv2
|
17 |
defined( 'ABSPATH' ) or die( 'Cheatin\' uh?' );
|
18 |
|
19 |
// Imagify defines
|
20 |
+
define( 'IMAGIFY_VERSION' , '1.5.7' );
|
21 |
define( 'IMAGIFY_SLUG' , 'imagify' );
|
22 |
define( 'IMAGIFY_SETTINGS_SLUG' , IMAGIFY_SLUG . '_settings' );
|
23 |
define( 'IMAGIFY_WEB_MAIN' , 'https://imagify.io' );
|
inc/3rd-party/nextgen-gallery/inc/classes/class-attachment.php
CHANGED
@@ -243,8 +243,9 @@ class Imagify_NGG_Attachment extends Imagify_Abstract_Attachment {
|
|
243 |
);
|
244 |
|
245 |
// Get file path & URL for original image
|
246 |
-
$attachment_path
|
247 |
-
$attachment_url
|
|
|
248 |
|
249 |
// Check if the full size is already optimized
|
250 |
if ( $this->is_optimized() && ( $this->get_optimization_level() == $optimization_level ) ) {
|
@@ -269,21 +270,42 @@ class Imagify_NGG_Attachment extends Imagify_Abstract_Attachment {
|
|
269 |
set_transient( 'imagify-ngg-async-in-progress-' . $id, true, 10 * MINUTE_IN_SECONDS );
|
270 |
|
271 |
// Get the resize values for the original size
|
272 |
-
$
|
273 |
$do_resize = get_imagify_option( 'resize_larger', false );
|
274 |
$resize_width = get_imagify_option( 'resize_larger_w' );
|
275 |
$attachment_size = @getimagesize( $attachment_path );
|
276 |
|
277 |
if ( $do_resize && isset( $attachment_size[0] ) && $resize_width < $attachment_size[0] ) {
|
278 |
-
|
279 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
280 |
|
281 |
// Optimize the original size
|
282 |
$response = do_imagify( $attachment_path, array(
|
283 |
'optimization_level' => $optimization_level,
|
284 |
-
'resize' => $resize,
|
285 |
'context' => 'ngg',
|
286 |
-
'
|
|
|
287 |
) );
|
288 |
$data = $this->fill_data( $data, $response, $id, $attachment_url );
|
289 |
|
@@ -303,7 +325,7 @@ class Imagify_NGG_Attachment extends Imagify_Abstract_Attachment {
|
|
303 |
|
304 |
// If we resized the original with success, we have to update the attachment metadata
|
305 |
// If not, WordPress keeps the old attachment size.
|
306 |
-
if ( $do_resize &&
|
307 |
$this->update_metadata_size();
|
308 |
}
|
309 |
|
243 |
);
|
244 |
|
245 |
// Get file path & URL for original image
|
246 |
+
$attachment_path = $this->get_original_path();
|
247 |
+
$attachment_url = $this->get_original_url();
|
248 |
+
$attachment_original_size = $this->get_original_size( false );
|
249 |
|
250 |
// Check if the full size is already optimized
|
251 |
if ( $this->is_optimized() && ( $this->get_optimization_level() == $optimization_level ) ) {
|
270 |
set_transient( 'imagify-ngg-async-in-progress-' . $id, true, 10 * MINUTE_IN_SECONDS );
|
271 |
|
272 |
// Get the resize values for the original size
|
273 |
+
$resized = false;
|
274 |
$do_resize = get_imagify_option( 'resize_larger', false );
|
275 |
$resize_width = get_imagify_option( 'resize_larger_w' );
|
276 |
$attachment_size = @getimagesize( $attachment_path );
|
277 |
|
278 |
if ( $do_resize && isset( $attachment_size[0] ) && $resize_width < $attachment_size[0] ) {
|
279 |
+
$resized_attachment_path = $this->resize( $attachment_path, $attachment_size, $resize_width );
|
280 |
+
|
281 |
+
if ( ! is_wp_error( $resized_attachment_path ) ) {
|
282 |
+
$backup_path = get_imagify_attachment_backup_path( $attachment_path );
|
283 |
+
$backup_path_info = pathinfo( $backup_path );
|
284 |
+
|
285 |
+
wp_mkdir_p( $backup_path_info['dirname'] );
|
286 |
+
|
287 |
+
// TO DO - check and send a error message if the backup can't be created
|
288 |
+
@copy( $attachment_path, $backup_path );
|
289 |
+
imagify_chmod_file( $backup_path );
|
290 |
+
|
291 |
+
@rename( $resized_attachment_path, $attachment_path );
|
292 |
+
imagify_chmod_file( $attachment_path );
|
293 |
+
|
294 |
+
// If resized temp file still exists, delete it
|
295 |
+
if ( file_exists( $resized_attachment_path ) ) {
|
296 |
+
unlink( $resized_attachment_path );
|
297 |
+
}
|
298 |
+
|
299 |
+
$resized = true;
|
300 |
+
}
|
301 |
+
}
|
302 |
|
303 |
// Optimize the original size
|
304 |
$response = do_imagify( $attachment_path, array(
|
305 |
'optimization_level' => $optimization_level,
|
|
|
306 |
'context' => 'ngg',
|
307 |
+
'resized' => $resized,
|
308 |
+
'original_size' => $attachment_original_size,
|
309 |
) );
|
310 |
$data = $this->fill_data( $data, $response, $id, $attachment_url );
|
311 |
|
325 |
|
326 |
// If we resized the original with success, we have to update the attachment metadata
|
327 |
// If not, WordPress keeps the old attachment size.
|
328 |
+
if ( $do_resize && $resized ) {
|
329 |
$this->update_metadata_size();
|
330 |
}
|
331 |
|
inc/classes/abstracts/abstract-attachment.php
CHANGED
@@ -380,4 +380,61 @@ class Imagify_Abstract_Attachment {
|
|
380 |
* @return void
|
381 |
*/
|
382 |
public function restore() {}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
383 |
}
|
380 |
* @return void
|
381 |
*/
|
382 |
public function restore() {}
|
383 |
+
|
384 |
+
/**
|
385 |
+
* Resize an image if bigger than the maximum width defined in the settings.
|
386 |
+
*
|
387 |
+
* @since 1.5.7
|
388 |
+
* @author Remy Perona
|
389 |
+
*
|
390 |
+
* @param string $attachment_path Path to the image
|
391 |
+
* @param array $attachment_sizes Array of original image dimensions
|
392 |
+
* @param int $max_width Maximum width defined in the settings
|
393 |
+
* @return string Path the the resized image or the original image if the resize failed
|
394 |
+
*/
|
395 |
+
function resize( $attachment_path, $attachment_sizes, $max_width ) {
|
396 |
+
$new_sizes = wp_constrain_dimensions( $attachment_sizes[0], $attachment_sizes[1], $max_width );
|
397 |
+
|
398 |
+
$editor = wp_get_image_editor( $attachment_path );
|
399 |
+
|
400 |
+
if ( is_wp_error( $editor ) ) {
|
401 |
+
return $editor;
|
402 |
+
}
|
403 |
+
|
404 |
+
$image_type = pathinfo( $attachment_path, PATHINFO_EXTENSION );
|
405 |
+
|
406 |
+
// try to correct for auto-rotation if the info is available
|
407 |
+
if ( function_exists( 'exif_read_data' ) && ( $image_type == 'jpg' || $image_type == 'jpeg' ) ) {
|
408 |
+
$exif = @exif_read_data( $attachment_path );
|
409 |
+
$orientation = is_array( $exif ) && array_key_exists( 'Orientation', $exif ) ? $exif['Orientation'] : 0;
|
410 |
+
|
411 |
+
switch( $orientation ) {
|
412 |
+
case 3:
|
413 |
+
$editor->rotate( 180 );
|
414 |
+
break;
|
415 |
+
case 6:
|
416 |
+
$editor->rotate( -90 );
|
417 |
+
break;
|
418 |
+
case 8:
|
419 |
+
$editor->rotate( 90 );
|
420 |
+
break;
|
421 |
+
}
|
422 |
+
}
|
423 |
+
|
424 |
+
$resized = $editor->resize( $new_sizes[0], $new_sizes[1], false );
|
425 |
+
|
426 |
+
if ( is_wp_error( $resized ) ) {
|
427 |
+
return $resized;
|
428 |
+
}
|
429 |
+
|
430 |
+
$resized_image_path = $editor->generate_filename( null );
|
431 |
+
|
432 |
+
$resized_image_saved = $editor->save( $resized_image_path );
|
433 |
+
|
434 |
+
if ( is_wp_error( $resized_image_saved ) ) {
|
435 |
+
return $resized_image_saved;
|
436 |
+
}
|
437 |
+
|
438 |
+
return $resized_image_path;
|
439 |
+
}
|
440 |
}
|
inc/classes/class-attachment.php
CHANGED
@@ -199,8 +199,9 @@ class Imagify_Attachment extends Imagify_Abstract_Attachment {
|
|
199 |
);
|
200 |
|
201 |
// Get file path & URL for original image
|
202 |
-
$attachment_path
|
203 |
-
$attachment_url
|
|
|
204 |
|
205 |
// Check if the attachment extension is allowed
|
206 |
if ( ! $id || ! wp_attachment_is_image( $id ) ) {
|
@@ -230,21 +231,42 @@ class Imagify_Attachment extends Imagify_Abstract_Attachment {
|
|
230 |
set_transient( 'imagify-async-in-progress-' . $id, true, 10 * MINUTE_IN_SECONDS );
|
231 |
|
232 |
// Get the resize values for the original size
|
233 |
-
|
234 |
$do_resize = get_imagify_option( 'resize_larger', false );
|
235 |
$resize_width = get_imagify_option( 'resize_larger_w' );
|
236 |
$attachment_size = @getimagesize( $attachment_path );
|
237 |
|
238 |
if ( $do_resize && isset( $attachment_size[0] ) && $resize_width < $attachment_size[0] ) {
|
239 |
-
|
240 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
241 |
|
242 |
// Optimize the original size
|
243 |
$response = do_imagify( $attachment_path, array(
|
244 |
'optimization_level' => $optimization_level,
|
245 |
-
'resize' => $resize,
|
246 |
'context' => 'wp',
|
247 |
-
'
|
|
|
248 |
) );
|
249 |
$data = $this->fill_data( $data, $response, $id, $attachment_url );
|
250 |
|
@@ -258,7 +280,7 @@ class Imagify_Attachment extends Imagify_Abstract_Attachment {
|
|
258 |
|
259 |
// If we resized the original with success, we have to update the attachment metadata
|
260 |
// If not, WordPress keeps the old attachment size.
|
261 |
-
if ( $do_resize &&
|
262 |
$this->update_metadata_size();
|
263 |
}
|
264 |
|
199 |
);
|
200 |
|
201 |
// Get file path & URL for original image
|
202 |
+
$attachment_path = $this->get_original_path();
|
203 |
+
$attachment_url = $this->get_original_url();
|
204 |
+
$attachment_original_size = $this->get_original_size( false );
|
205 |
|
206 |
// Check if the attachment extension is allowed
|
207 |
if ( ! $id || ! wp_attachment_is_image( $id ) ) {
|
231 |
set_transient( 'imagify-async-in-progress-' . $id, true, 10 * MINUTE_IN_SECONDS );
|
232 |
|
233 |
// Get the resize values for the original size
|
234 |
+
$resized = false;
|
235 |
$do_resize = get_imagify_option( 'resize_larger', false );
|
236 |
$resize_width = get_imagify_option( 'resize_larger_w' );
|
237 |
$attachment_size = @getimagesize( $attachment_path );
|
238 |
|
239 |
if ( $do_resize && isset( $attachment_size[0] ) && $resize_width < $attachment_size[0] ) {
|
240 |
+
$resized_attachment_path = $this->resize( $attachment_path, $attachment_size, $resize_width );
|
241 |
+
|
242 |
+
if ( ! is_wp_error( $resized_attachment_path ) ) {
|
243 |
+
$backup_path = get_imagify_attachment_backup_path( $attachment_path );
|
244 |
+
$backup_path_info = pathinfo( $backup_path );
|
245 |
+
|
246 |
+
wp_mkdir_p( $backup_path_info['dirname'] );
|
247 |
+
|
248 |
+
// TO DO - check and send a error message if the backup can't be created
|
249 |
+
@copy( $attachment_path, $backup_path );
|
250 |
+
imagify_chmod_file( $backup_path );
|
251 |
+
|
252 |
+
@rename( $resized_attachment_path, $attachment_path );
|
253 |
+
imagify_chmod_file( $attachment_path );
|
254 |
+
|
255 |
+
// If resized temp file still exists, delete it
|
256 |
+
if ( file_exists( $resized_attachment_path ) ) {
|
257 |
+
unlink( $resized_attachment_path );
|
258 |
+
}
|
259 |
+
|
260 |
+
$resized = true;
|
261 |
+
}
|
262 |
+
}
|
263 |
|
264 |
// Optimize the original size
|
265 |
$response = do_imagify( $attachment_path, array(
|
266 |
'optimization_level' => $optimization_level,
|
|
|
267 |
'context' => 'wp',
|
268 |
+
'resized' => $resized,
|
269 |
+
'original_size' => $attachment_original_size,
|
270 |
) );
|
271 |
$data = $this->fill_data( $data, $response, $id, $attachment_url );
|
272 |
|
280 |
|
281 |
// If we resized the original with success, we have to update the attachment metadata
|
282 |
// If not, WordPress keeps the old attachment size.
|
283 |
+
if ( $do_resize && $resized ) {
|
284 |
$this->update_metadata_size();
|
285 |
}
|
286 |
|
inc/functions/process.php
CHANGED
@@ -9,7 +9,6 @@ defined( 'ABSPATH' ) or die( 'Cheatin\' uh?' );
|
|
9 |
* @param string $file_path Absolute path to the image file.
|
10 |
* @param bool $backup Force a backup of the original file.
|
11 |
* @param int $optimization_level The optimization level (2=ultra, 1=aggressive, 0=normal).
|
12 |
-
* @param array $resize The resize parameters (with & height).
|
13 |
* @param bool $keep_exif To keep exif data or not
|
14 |
* @return obj|array Error message | Optimized image data
|
15 |
*/
|
@@ -19,10 +18,10 @@ function do_imagify( $file_path, $args = array() ) {
|
|
19 |
array(
|
20 |
'backup' => get_imagify_option( 'backup', false ),
|
21 |
'optimization_level' => get_imagify_option( 'optimization_level', 1 ),
|
22 |
-
'resize' => array(),
|
23 |
'keep_exif' => get_imagify_option( 'exif', false ),
|
24 |
'context' => 'wp',
|
25 |
-
'
|
|
|
26 |
),
|
27 |
$args
|
28 |
);
|
@@ -92,7 +91,6 @@ function do_imagify( $file_path, $args = array() ) {
|
|
92 |
array(
|
93 |
'aggressive' => ( 1 === (int) $args['optimization_level'] ) ? true : false,
|
94 |
'ultra' => ( 2 === (int) $args['optimization_level'] ) ? true : false,
|
95 |
-
'resize' => $args['resize'],
|
96 |
'keep_exif' => $args['keep_exif'],
|
97 |
'context' => $args['context'],
|
98 |
'original_size' => $args['original_size']
|
@@ -108,7 +106,7 @@ function do_imagify( $file_path, $args = array() ) {
|
|
108 |
}
|
109 |
|
110 |
// Create a backup file
|
111 |
-
if ( 'wp' === $args['context'] && $args['backup'] ) {
|
112 |
$backup_path = get_imagify_attachment_backup_path( $file_path );
|
113 |
$backup_path_info = pathinfo( $backup_path );
|
114 |
|
9 |
* @param string $file_path Absolute path to the image file.
|
10 |
* @param bool $backup Force a backup of the original file.
|
11 |
* @param int $optimization_level The optimization level (2=ultra, 1=aggressive, 0=normal).
|
|
|
12 |
* @param bool $keep_exif To keep exif data or not
|
13 |
* @return obj|array Error message | Optimized image data
|
14 |
*/
|
18 |
array(
|
19 |
'backup' => get_imagify_option( 'backup', false ),
|
20 |
'optimization_level' => get_imagify_option( 'optimization_level', 1 ),
|
|
|
21 |
'keep_exif' => get_imagify_option( 'exif', false ),
|
22 |
'context' => 'wp',
|
23 |
+
'resized' => false,
|
24 |
+
'original_size' => 0,
|
25 |
),
|
26 |
$args
|
27 |
);
|
91 |
array(
|
92 |
'aggressive' => ( 1 === (int) $args['optimization_level'] ) ? true : false,
|
93 |
'ultra' => ( 2 === (int) $args['optimization_level'] ) ? true : false,
|
|
|
94 |
'keep_exif' => $args['keep_exif'],
|
95 |
'context' => $args['context'],
|
96 |
'original_size' => $args['original_size']
|
106 |
}
|
107 |
|
108 |
// Create a backup file
|
109 |
+
if ( 'wp' === $args['context'] && $args['backup'] && ! $args['resized'] ) {
|
110 |
$backup_path = get_imagify_attachment_backup_path( $file_path );
|
111 |
$backup_path_info = pathinfo( $backup_path );
|
112 |
|
readme.txt
CHANGED
@@ -3,7 +3,7 @@ Contributors: wp_media
|
|
3 |
Tags: compress image, images, performance, optimization, photos, upload, resize, gif, png, jpg, reduce image size, retina
|
4 |
Requires at least: 3.7.0
|
5 |
Tested up to: 4.6
|
6 |
-
Stable tag: 1.5.
|
7 |
License: GPLv2 or later
|
8 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
9 |
|
@@ -135,6 +135,10 @@ When the plugin is disabled, your existing images remain optimized. Backups of t
|
|
135 |
3. Media Page
|
136 |
|
137 |
== Changelog ==
|
|
|
|
|
|
|
|
|
138 |
= 1.5.6 =
|
139 |
* Improvement
|
140 |
* Dynamically update from the API the maximum image size allowed in bulk optimization
|
3 |
Tags: compress image, images, performance, optimization, photos, upload, resize, gif, png, jpg, reduce image size, retina
|
4 |
Requires at least: 3.7.0
|
5 |
Tested up to: 4.6
|
6 |
+
Stable tag: 1.5.7
|
7 |
License: GPLv2 or later
|
8 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
9 |
|
135 |
3. Media Page
|
136 |
|
137 |
== Changelog ==
|
138 |
+
= 1.5.7 =
|
139 |
+
* Improvement
|
140 |
+
* Resize images bigger than the maximum width defined in the settings using WP Image Editor instead of Imagify API
|
141 |
+
|
142 |
= 1.5.6 =
|
143 |
* Improvement
|
144 |
* Dynamically update from the API the maximum image size allowed in bulk optimization
|