WordPress.org

Plugin Directory

Changeset 450014


Ignore:
Timestamp:
10/11/11 20:06:25 (3 years ago)
Author:
alexdunae
Message:

bulk smush.it will no longer re-smush images that were successful

Location:
wp-smushit/trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • wp-smushit/trunk/bulk.php

    r409526 r450014  
    99    if ( empty($_POST) ): // instructions page 
    1010?> 
    11   <p>This tool will run all of the images in your media library through the WP Smush.it web service.</p> 
     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> 
    1212   
    1313  <p>It uploads each and every file to Yahoo! and then downloads the resulting file. It can take a long time.</p> 
    1414   
    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> 
     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> 
    1616   
    1717  <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> 
     
    3636      foreach( $attachments as $attachment ) { 
    3737        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'] ); 
     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          } 
    4165        } 
    4266        echo "</p>"; 
  • wp-smushit/trunk/readme.txt

    r409526 r450014  
    11=== WP Smush.it === 
    22Plugin Name: WP Smush.it 
    3 Version: 1.4.1 
     3Version: 1.4.2 
    44Author: Dialect 
    55Author URI: http://dialect.ca/?wp_smush_it 
     
    88Requires at least: 2.9 
    99Tested up to: 3.2.1 
    10 Stable tag: 1.4.1 
     10Stable tag: 1.4.2 
    1111 
    1212Reduce image file sizes and improve performance using the <a href="http://smush.it/">Smush.it</a> API within WordPress. 
     
    4949 
    5050== 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 
    5157 
    5258= 1.4.0 
  • wp-smushit/trunk/wp-smushit.php

    r409526 r450014  
    22/** 
    33 * Integrate the Smush.it API into WordPress. 
    4  * @version 1.4.1 
     4 * @version 1.4.2 
    55 * @package WP_SmushIt 
    66 */ 
     
    1010Description: Reduce image file sizes and improve performance using the <a href="http://smush.it/">Smush.it</a> API within WordPress. 
    1111Author: Dialect 
    12 Version: 1.4.1 
     12Version: 1.4.2 
    1313Author URI: http://dialect.ca/ 
    1414*/ 
     
    2929 
    3030define('WP_SMUSHIT_DOMAIN', 'wp_smushit'); 
    31 define('WP_SMUSHIT_UA', 'WP Smush.it/1.4.1 (+http://dialect.ca/code/wp-smushit)'); 
     31define('WP_SMUSHIT_UA', 'WP Smush.it/1.4.2 (+http://dialect.ca/code/wp-smushit)'); 
    3232define('WP_SMUSHIT_PLUGIN_DIR', dirname(plugin_basename(__FILE__))); 
    3333 
     
    199199} 
    200200 
     201function 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 
    201214 
    202215/** 
     
    208221 * Called after `wp_generate_attachment_metadata` is completed. 
    209222 */ 
    210 function wp_smushit_resize_from_meta_data($meta, $ID = null) { 
     223function wp_smushit_resize_from_meta_data($meta, $ID = null, $force_resmush = true) { 
    211224    $file_path = $meta['file']; 
    212225    $store_absolute_path = true; 
     
    220233    } 
    221234 
    222     list($file, $msg) = wp_smushit($file_path); 
    223  
    224     $meta['file'] = $file; 
    225     $meta['wp_smushit'] = $msg; 
     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 
    226241 
    227242    // strip absolute path for Wordpress >= 2.6.2 
     
    239254 
    240255    foreach($meta['sizes'] as $size => $data) { 
     256      if ( !$force_resmush && wp_smushit_should_resmush( @$meta['sizes'][$size]['wp_smushit'] ) === FALSE ) { 
     257      continue; 
     258      } 
     259 
    241260        list($smushed_file, $results) = wp_smushit($base_dir . $data['file']); 
    242  
    243261        $meta['sizes'][$size]['file'] = str_replace($base_dir, '', $smushed_file); 
    244262        $meta['sizes'][$size]['wp_smushit'] = $results; 
Note: See TracChangeset for help on using the changeset viewer.