Smush Image Compression and Optimization - Version 1.4.2

Version Description

Download this release

Release Info

Developer alexdunae
Plugin Icon 128x128 Smush Image Compression and Optimization
Version 1.4.2
Comparing to
See all releases

Code changes from version 1.4.1 to 1.4.2

Files changed (3) hide show
  1. bulk.php +29 -5
  2. readme.txt +8 -2
  3. wp-smushit.php +26 -8
bulk.php CHANGED
@@ -8,11 +8,11 @@
8
  else:
9
  if ( empty($_POST) ): // instructions page
10
  ?>
11
- <p>This tool will run all of the images in your media library through the WP Smush.it web service.</p>
12
 
13
  <p>It uploads each and every file to Yahoo! and then downloads the resulting file. It can take a long time.</p>
14
 
15
- <p>We found <?php echo sizeof($attachments); ?> images in your media library. Be forewarned, <strong>it will take <em>at least</em> <?php echo (sizeof($attachments) * 3 / 60); ?> minutes</strong> to process all these images.</p>
16
 
17
  <p><em>N.B. If your server <tt>gzip</tt>s content you may not see the progress updates as your files are processed.</em></p>
18
 
@@ -35,9 +35,33 @@
35
 
36
  foreach( $attachments as $attachment ) {
37
  printf( "<p>Processing <strong>%s</strong>&hellip;<br>", esc_html($attachment->post_name) );
38
- $meta = wp_smushit_resize_from_meta_data( wp_get_attachment_metadata( $attachment->ID, true ), $attachment->ID );
39
- foreach( $meta['sizes'] as $size ) {
40
- printf( "– %s<br>", $size['wp_smushit'] );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
41
  }
42
  echo "</p>";
43
 
8
  else:
9
  if ( empty($_POST) ): // instructions page
10
  ?>
11
+ <p>This tool will run all of the images in your media library through the WP Smush.it web service. It won't re-smush images that were successfully smushed before. It will retry images that were not successfully smushed.</p>
12
 
13
  <p>It uploads each and every file to Yahoo! and then downloads the resulting file. It can take a long time.</p>
14
 
15
+ <p>We found <?php echo sizeof($attachments); ?> images in your media library. Be forewarned, <strong>it will take <em>at least</em> <?php echo (sizeof($attachments) * 3 / 60); ?> minutes</strong> to process all these images if they have never been smushed before.</p>
16
 
17
  <p><em>N.B. If your server <tt>gzip</tt>s content you may not see the progress updates as your files are processed.</em></p>
18
 
35
 
36
  foreach( $attachments as $attachment ) {
37
  printf( "<p>Processing <strong>%s</strong>&hellip;<br>", esc_html($attachment->post_name) );
38
+ $original_meta = wp_get_attachment_metadata( $attachment->ID, true );
39
+
40
+ $meta = wp_smushit_resize_from_meta_data( $original_meta, $attachment->ID, false );
41
+
42
+ printf( "– %dx%d: ", intval($meta['width']), intval($meta['height']) );
43
+
44
+ if ( $original_meta['wp_smushit'] == $meta['wp_smushit'] ) {
45
+ echo 'already smushed';
46
+ } else {
47
+ echo $meta['wp_smushit'];
48
+ }
49
+ echo '<br>';
50
+
51
+
52
+
53
+ if ( isset( $meta['sizes'] ) && is_array( $meta['sizes'] ) ) {
54
+ foreach( $meta['sizes'] as $size_name => $size ) {
55
+ printf( "– %dx%d: ", intval($size['width']), intval($size['height']) );
56
+
57
+ if ( $original_meta['sizes'][$size_name]['wp_smushit'] == $size['wp_smushit'] ) {
58
+ echo 'already smushed';
59
+ } else {
60
+ echo $size['wp_smushit'];
61
+ }
62
+ echo '<br>';
63
+
64
+ }
65
  }
66
  echo "</p>";
67
 
readme.txt CHANGED
@@ -1,13 +1,13 @@
1
  === WP Smush.it ===
2
  Plugin Name: WP Smush.it
3
- Version: 1.4.1
4
  Author: Dialect
5
  Author URI: http://dialect.ca/?wp_smush_it
6
  Contributors: alexdunae
7
  Tags: images, image, attachments, attachment
8
  Requires at least: 2.9
9
  Tested up to: 3.2.1
10
- Stable tag: 1.4.1
11
 
12
  Reduce image file sizes and improve performance using the <a href="http://smush.it/">Smush.it</a> API within WordPress.
13
 
@@ -49,6 +49,12 @@ Plugin updates are announced on [http://www.twitter.com/TheCHANGELOG](http://www
49
 
50
  == Changelog ==
51
 
 
 
 
 
 
 
52
  = 1.4.0
53
  * bulk smush.it
54
 
1
  === WP Smush.it ===
2
  Plugin Name: WP Smush.it
3
+ Version: 1.4.2
4
  Author: Dialect
5
  Author URI: http://dialect.ca/?wp_smush_it
6
  Contributors: alexdunae
7
  Tags: images, image, attachments, attachment
8
  Requires at least: 2.9
9
  Tested up to: 3.2.1
10
+ Stable tag: 1.4.2
11
 
12
  Reduce image file sizes and improve performance using the <a href="http://smush.it/">Smush.it</a> API within WordPress.
13
 
49
 
50
  == Changelog ==
51
 
52
+ = 1.4.2
53
+ * bulk smush.it will no longer re-smush images that were successful
54
+
55
+ = 1.4.1
56
+ * bug fixes
57
+
58
  = 1.4.0
59
  * bulk smush.it
60
 
wp-smushit.php CHANGED
@@ -1,7 +1,7 @@
1
  <?php
2
  /**
3
  * Integrate the Smush.it API into WordPress.
4
- * @version 1.4.1
5
  * @package WP_SmushIt
6
  */
7
  /*
@@ -9,7 +9,7 @@ Plugin Name: WP Smush.it
9
  Plugin URI: http://dialect.ca/code/wp-smushit/
10
  Description: Reduce image file sizes and improve performance using the <a href="http://smush.it/">Smush.it</a> API within WordPress.
11
  Author: Dialect
12
- Version: 1.4.1
13
  Author URI: http://dialect.ca/
14
  */
15
 
@@ -28,7 +28,7 @@ define('SMUSHIT_REQ_URL', 'http://www.smushit.com/ysmush.it/ws.php?img=%s');
28
  define('SMUSHIT_BASE_URL', 'http://www.smushit.com/');
29
 
30
  define('WP_SMUSHIT_DOMAIN', 'wp_smushit');
31
- define('WP_SMUSHIT_UA', 'WP Smush.it/1.4.1 (+http://dialect.ca/code/wp-smushit)');
32
  define('WP_SMUSHIT_PLUGIN_DIR', dirname(plugin_basename(__FILE__)));
33
 
34
 
@@ -198,6 +198,19 @@ function wp_smushit($file) {
198
  return array($file, $results_msg);
199
  }
200
 
 
 
 
 
 
 
 
 
 
 
 
 
 
201
 
202
  /**
203
  * Read the image paths from an attachment's meta data and process each image
@@ -207,7 +220,7 @@ function wp_smushit($file) {
207
  *
208
  * Called after `wp_generate_attachment_metadata` is completed.
209
  */
210
- function wp_smushit_resize_from_meta_data($meta, $ID = null) {
211
  $file_path = $meta['file'];
212
  $store_absolute_path = true;
213
  $upload_dir = wp_upload_dir();
@@ -219,10 +232,12 @@ function wp_smushit_resize_from_meta_data($meta, $ID = null) {
219
  $file_path = $upload_path . $file_path;
220
  }
221
 
222
- list($file, $msg) = wp_smushit($file_path);
 
 
 
 
223
 
224
- $meta['file'] = $file;
225
- $meta['wp_smushit'] = $msg;
226
 
227
  // strip absolute path for Wordpress >= 2.6.2
228
  if ( FALSE === $store_absolute_path ) {
@@ -238,8 +253,11 @@ function wp_smushit_resize_from_meta_data($meta, $ID = null) {
238
 
239
 
240
  foreach($meta['sizes'] as $size => $data) {
241
- list($smushed_file, $results) = wp_smushit($base_dir . $data['file']);
 
 
242
 
 
243
  $meta['sizes'][$size]['file'] = str_replace($base_dir, '', $smushed_file);
244
  $meta['sizes'][$size]['wp_smushit'] = $results;
245
  }
1
  <?php
2
  /**
3
  * Integrate the Smush.it API into WordPress.
4
+ * @version 1.4.2
5
  * @package WP_SmushIt
6
  */
7
  /*
9
  Plugin URI: http://dialect.ca/code/wp-smushit/
10
  Description: Reduce image file sizes and improve performance using the <a href="http://smush.it/">Smush.it</a> API within WordPress.
11
  Author: Dialect
12
+ Version: 1.4.2
13
  Author URI: http://dialect.ca/
14
  */
15
 
28
  define('SMUSHIT_BASE_URL', 'http://www.smushit.com/');
29
 
30
  define('WP_SMUSHIT_DOMAIN', 'wp_smushit');
31
+ define('WP_SMUSHIT_UA', 'WP Smush.it/1.4.2 (+http://dialect.ca/code/wp-smushit)');
32
  define('WP_SMUSHIT_PLUGIN_DIR', dirname(plugin_basename(__FILE__)));
33
 
34
 
198
  return array($file, $results_msg);
199
  }
200
 
201
+ function wp_smushit_should_resmush($previous_status) {
202
+ if ( !$previous_status || empty($previous_status) ) {
203
+ return TRUE;
204
+ }
205
+
206
+ if ( stripos($previous_status, 'no savings') !== FALSE || stripos($previous_status, 'reduced') !== FALSE ) {
207
+ return FALSE;
208
+ }
209
+
210
+ // otherwise an error
211
+ return TRUE;
212
+ }
213
+
214
 
215
  /**
216
  * Read the image paths from an attachment's meta data and process each image
220
  *
221
  * Called after `wp_generate_attachment_metadata` is completed.
222
  */
223
+ function wp_smushit_resize_from_meta_data($meta, $ID = null, $force_resmush = true) {
224
  $file_path = $meta['file'];
225
  $store_absolute_path = true;
226
  $upload_dir = wp_upload_dir();
232
  $file_path = $upload_path . $file_path;
233
  }
234
 
235
+ if ( $force_resmush || wp_smushit_should_resmush( @$meta['wp_smushit'] ) ) {
236
+ list($file, $msg) = wp_smushit($file_path);
237
+ $meta['file'] = $file;
238
+ $meta['wp_smushit'] = $msg;
239
+ }
240
 
 
 
241
 
242
  // strip absolute path for Wordpress >= 2.6.2
243
  if ( FALSE === $store_absolute_path ) {
253
 
254
 
255
  foreach($meta['sizes'] as $size => $data) {
256
+ if ( !$force_resmush && wp_smushit_should_resmush( @$meta['sizes'][$size]['wp_smushit'] ) === FALSE ) {
257
+ continue;
258
+ }
259
 
260
+ list($smushed_file, $results) = wp_smushit($base_dir . $data['file']);
261
  $meta['sizes'][$size]['file'] = str_replace($base_dir, '', $smushed_file);
262
  $meta['sizes'][$size]['wp_smushit'] = $results;
263
  }