EWWW Image Optimizer - Version 4.5.2

Version Description

  • added: automatic migration to move image paths from absolute to relative
  • changed: default quality for PNG to JPG did not match WordPress default
  • fixed: legacy absolute paths not matched during bulk scanner when relative matching is enabled
  • fixed: PNG to JPG auto-convert produces larger JPG images in some cases
Download this release

Release Info

Developer nosilver4u
Plugin Icon 128x128 EWWW Image Optimizer
Version 4.5.2
Comparing to
See all releases

Code changes from version 4.5.1 to 4.5.2

aux-optimize.php CHANGED
@@ -156,7 +156,7 @@ function ewww_image_optimizer_aux_images_table() {
156
  echo '<br /><table class="wp-list-table widefat media" cellspacing="0"><thead><tr><th>&nbsp;</th><th>' . esc_html__( 'Filename', 'ewww-image-optimizer' ) . '</th><th>' . esc_html__( 'Image Type', 'ewww-image-optimizer' ) . '</th><th>' . esc_html__( 'Image Optimizer', 'ewww-image-optimizer' ) . '</th></tr></thead>';
157
  $alternate = true;
158
  foreach ( $already_optimized as $optimized_image ) {
159
- $file = ewww_image_optimizer_relative_path_replace( $optimized_image['path'] );
160
  $image_name = str_replace( ABSPATH, '', $file );
161
  $image_url = esc_url( site_url( 'wp-includes/images/media/default.png' ) );
162
  ewwwio_debug_message( "name is $image_name after replacing ABSPATH" );
@@ -188,7 +188,7 @@ function ewww_image_optimizer_aux_images_table() {
188
  }
189
  ?>
190
  id="ewww-image-<?php echo $optimized_image['id']; ?>">
191
- <td style='width:80px' class='column-icon'>&nbsp;</td>
192
  <td class='title'><?php echo $image_name; ?></td>
193
  <td><?php echo $type; ?></td>
194
  <td>
@@ -216,7 +216,7 @@ function ewww_image_optimizer_aux_images_table() {
216
  }
217
  ?>
218
  id="ewww-image-<?php echo $optimized_image['id']; ?>">
219
- <td style='width:80px' class='column-icon'><img width='50' height='50' src="<?php echo $image_url; ?>" /></td>
220
  <td class='title'>...<?php echo $image_name; ?></td>
221
  <td><?php echo $type; ?></td>
222
  <td>
@@ -508,7 +508,7 @@ function ewww_image_optimizer_image_scan( $dir, $started = 0 ) {
508
  continue;
509
  }
510
  ewwwio_debug_message( "queuing $path" );
511
- $path = ewww_image_optimizer_relative_path_remove( $path );
512
  if ( seems_utf8( $path ) ) {
513
  $utf8_file_path = $path;
514
  } else {
@@ -558,7 +558,7 @@ function ewww_image_optimizer_aux_images_convert() {
558
  if ( empty( $record['image_md5'] ) ) {
559
  continue;
560
  }
561
- $record['path'] = ewww_image_optimizer_relative_path_replace( $record['path'] );
562
  $image_md5 = md5_file( $record['path'] );
563
  if ( $image_md5 === $record['image_md5'] ) {
564
  $filesize = filesize( $record['path'] );
@@ -680,7 +680,7 @@ function ewww_image_optimizer_aux_images_script( $hook = '' ) {
680
  // This is a brand new image.
681
  if ( preg_match( '/^image\/(jpeg|png|gif)/', $mimetype ) && empty( $already_optimized ) ) {
682
  $slide_paths[] = array(
683
- 'path' => ewww_image_optimizer_relative_path_remove( $path ),
684
  'orig_size' => $image_size,
685
  );
686
  // This is a changed image.
156
  echo '<br /><table class="wp-list-table widefat media" cellspacing="0"><thead><tr><th>&nbsp;</th><th>' . esc_html__( 'Filename', 'ewww-image-optimizer' ) . '</th><th>' . esc_html__( 'Image Type', 'ewww-image-optimizer' ) . '</th><th>' . esc_html__( 'Image Optimizer', 'ewww-image-optimizer' ) . '</th></tr></thead>';
157
  $alternate = true;
158
  foreach ( $already_optimized as $optimized_image ) {
159
+ $file = ewww_image_optimizer_absolutize_path( $optimized_image['path'] );
160
  $image_name = str_replace( ABSPATH, '', $file );
161
  $image_url = esc_url( site_url( 'wp-includes/images/media/default.png' ) );
162
  ewwwio_debug_message( "name is $image_name after replacing ABSPATH" );
188
  }
189
  ?>
190
  id="ewww-image-<?php echo $optimized_image['id']; ?>">
191
+ <td style='max-width:20px' class='column-icon'>&nbsp;</td>
192
  <td class='title'><?php echo $image_name; ?></td>
193
  <td><?php echo $type; ?></td>
194
  <td>
216
  }
217
  ?>
218
  id="ewww-image-<?php echo $optimized_image['id']; ?>">
219
+ <td style='max-width:50px;' class='column-icon'><img width='50' src="<?php echo $image_url; ?>" /></td>
220
  <td class='title'>...<?php echo $image_name; ?></td>
221
  <td><?php echo $type; ?></td>
222
  <td>
508
  continue;
509
  }
510
  ewwwio_debug_message( "queuing $path" );
511
+ $path = ewww_image_optimizer_relativize_path( $path );
512
  if ( seems_utf8( $path ) ) {
513
  $utf8_file_path = $path;
514
  } else {
558
  if ( empty( $record['image_md5'] ) ) {
559
  continue;
560
  }
561
+ $record['path'] = ewww_image_optimizer_absolutize_path( $record['path'] );
562
  $image_md5 = md5_file( $record['path'] );
563
  if ( $image_md5 === $record['image_md5'] ) {
564
  $filesize = filesize( $record['path'] );
680
  // This is a brand new image.
681
  if ( preg_match( '/^image\/(jpeg|png|gif)/', $mimetype ) && empty( $already_optimized ) ) {
682
  $slide_paths[] = array(
683
+ 'path' => ewww_image_optimizer_relativize_path( $path ),
684
  'orig_size' => $image_size,
685
  );
686
  // This is a changed image.
bulk.php CHANGED
@@ -25,6 +25,7 @@ function ewww_image_optimizer_bulk_preview() {
25
  echo '</p></div></div>';
26
  return;
27
  }
 
28
  if ( ewww_image_optimizer_get_option( 'ewww_image_optimizer_cloud_key' ) ) {
29
  echo '<span><a id="ewww-bulk-credits-available" target="_blank" class="page-title-action" style="float:right;" href="https://ewww.io/my-account/">' . esc_html__( 'Image credits available:', 'ewww-image-optimizer' ) . ' ' . ewww_image_optimizer_cloud_quota() . '</a></span>';
30
  }
@@ -42,7 +43,7 @@ function ewww_image_optimizer_bulk_preview() {
42
  }
43
  // Create the html for the bulk optimize form and status divs.
44
  ewww_image_optimizer_bulk_head_output();
45
- echo '<div id="ewww-bulk-forms">';
46
  if ( $fullsize_count < 1 ) {
47
  echo '<p>' . esc_html__( 'You do not appear to have uploaded any images yet.', 'ewww-image-optimizer' ) . '</p>';
48
  } else {
@@ -108,12 +109,12 @@ function ewww_image_optimizer_bulk_head_output() {
108
  </div>
109
  </div>
110
  </div>
111
- <form class="ewww-bulk-form">
112
  <p><label for="ewww-force" style="font-weight: bold"><?php esc_html_e( 'Force re-optimize', 'ewww-image-optimizer' ); ?></label><?php echo ewwwio_help_link( 'https://docs.ewww.io/article/65-force-re-optimization', '5bb640a7042863158cc711cd' ); ?>
113
  &emsp;<input type="checkbox" id="ewww-force" name="ewww-force"<?php echo ( get_transient( 'ewww_image_optimizer_force_reopt' ) ) ? ' checked' : ''; ?>>
114
  &nbsp;<?php esc_html_e( 'Previously optimized images will be skipped by default, check this box before scanning to override.', 'ewww-image-optimizer' ); ?></p>
115
  <p><label for="ewww-delay" style="font-weight: bold"><?php esc_html_e( 'Choose how long to pause between images (in seconds, 0 = disabled)', 'ewww-image-optimizer' ); ?></label>&emsp;<input type="text" id="ewww-delay" name="ewww-delay" value="<?php echo $delay; ?>"></p>
116
- <div id="ewww-delay-slider" style="width:50%"></div>
117
  </form>
118
  <?php
119
  }
@@ -533,7 +534,7 @@ function ewww_image_optimizer_optimized_list() {
533
  while ( $already_optimized = $ewwwdb->get_results( "SELECT id,path,image_size,pending,attachment_id,updated FROM $ewwwdb->ewwwio_images LIMIT $offset,$max_query", ARRAY_A ) ) {
534
  $ewwwdb->flush();
535
  foreach ( $already_optimized as $optimized ) {
536
- $optimized_path = ewww_image_optimizer_relative_path_replace( $optimized['path'] );
537
  // Check for duplicate records.
538
  if ( ! empty( $optimized_list[ $optimized_path ] ) && ! empty( $optimized_list[ $optimized_path ]['id'] ) ) {
539
  $optimized = ewww_image_optimizer_remove_duplicate_records( array( $optimized_list[ $optimized_path ]['id'], $optimized['id'] ) );
@@ -903,7 +904,7 @@ function ewww_image_optimizer_media_scan( $hook = '' ) {
903
  $ewwwdb->update(
904
  $ewwwdb->ewwwio_images,
905
  array(
906
- 'path' => ewww_image_optimizer_relative_path_remove( $ims_path ),
907
  'updated' => $optimized_list[ $ims_temp_path ]['updated'],
908
  ),
909
  array(
@@ -1101,7 +1102,7 @@ function ewww_image_optimizer_media_scan( $hook = '' ) {
1101
  }
1102
  ewww_image_optimizer_debug_log();
1103
  $images[ $file_path ] = array(
1104
- 'path' => ewww_image_optimizer_relative_path_remove( $utf8_file_path ),
1105
  'gallery' => 'media',
1106
  'orig_size' => $image_size,
1107
  'attachment_id' => $selected_id,
25
  echo '</p></div></div>';
26
  return;
27
  }
28
+ echo '<div id="ewww-bulk-warning" class="ewww-bulk-info notice notice-warning"><p>' . esc_html__( 'Bulk Optimization will alter your original images and cannot be undone. Please be sure you have a backup of your images before proceeding.', 'ewww-image-optimizer' ) . '</p></div>';
29
  if ( ewww_image_optimizer_get_option( 'ewww_image_optimizer_cloud_key' ) ) {
30
  echo '<span><a id="ewww-bulk-credits-available" target="_blank" class="page-title-action" style="float:right;" href="https://ewww.io/my-account/">' . esc_html__( 'Image credits available:', 'ewww-image-optimizer' ) . ' ' . ewww_image_optimizer_cloud_quota() . '</a></span>';
31
  }
43
  }
44
  // Create the html for the bulk optimize form and status divs.
45
  ewww_image_optimizer_bulk_head_output();
46
+ echo '<div id="ewww-bulk-forms" style="border: solid 1px #e5e5e5; background: #fff; padding: 0 10px 12px; margin: 10px 0;">';
47
  if ( $fullsize_count < 1 ) {
48
  echo '<p>' . esc_html__( 'You do not appear to have uploaded any images yet.', 'ewww-image-optimizer' ) . '</p>';
49
  } else {
109
  </div>
110
  </div>
111
  </div>
112
+ <form class="ewww-bulk-form" style="border: solid 1px #e5e5e5; background: #fff; padding: 10px;">
113
  <p><label for="ewww-force" style="font-weight: bold"><?php esc_html_e( 'Force re-optimize', 'ewww-image-optimizer' ); ?></label><?php echo ewwwio_help_link( 'https://docs.ewww.io/article/65-force-re-optimization', '5bb640a7042863158cc711cd' ); ?>
114
  &emsp;<input type="checkbox" id="ewww-force" name="ewww-force"<?php echo ( get_transient( 'ewww_image_optimizer_force_reopt' ) ) ? ' checked' : ''; ?>>
115
  &nbsp;<?php esc_html_e( 'Previously optimized images will be skipped by default, check this box before scanning to override.', 'ewww-image-optimizer' ); ?></p>
116
  <p><label for="ewww-delay" style="font-weight: bold"><?php esc_html_e( 'Choose how long to pause between images (in seconds, 0 = disabled)', 'ewww-image-optimizer' ); ?></label>&emsp;<input type="text" id="ewww-delay" name="ewww-delay" value="<?php echo $delay; ?>"></p>
117
+ <div id="ewww-delay-slider" style="margin: 0 0 15px 10px; max-width:500px"></div>
118
  </form>
119
  <?php
120
  }
534
  while ( $already_optimized = $ewwwdb->get_results( "SELECT id,path,image_size,pending,attachment_id,updated FROM $ewwwdb->ewwwio_images LIMIT $offset,$max_query", ARRAY_A ) ) {
535
  $ewwwdb->flush();
536
  foreach ( $already_optimized as $optimized ) {
537
+ $optimized_path = ewww_image_optimizer_absolutize_path( $optimized['path'] );
538
  // Check for duplicate records.
539
  if ( ! empty( $optimized_list[ $optimized_path ] ) && ! empty( $optimized_list[ $optimized_path ]['id'] ) ) {
540
  $optimized = ewww_image_optimizer_remove_duplicate_records( array( $optimized_list[ $optimized_path ]['id'], $optimized['id'] ) );
904
  $ewwwdb->update(
905
  $ewwwdb->ewwwio_images,
906
  array(
907
+ 'path' => ewww_image_optimizer_relativize_path( $ims_path ),
908
  'updated' => $optimized_list[ $ims_temp_path ]['updated'],
909
  ),
910
  array(
1102
  }
1103
  ewww_image_optimizer_debug_log();
1104
  $images[ $file_path ] = array(
1105
+ 'path' => ewww_image_optimizer_relativize_path( $utf8_file_path ),
1106
  'gallery' => 'media',
1107
  'orig_size' => $image_size,
1108
  'attachment_id' => $selected_id,
changelog.txt CHANGED
@@ -1,3 +1,9 @@
 
 
 
 
 
 
1
  = 4.5.1 =
2
  * changed: optimization results are tracked by relative urls instead of absolute ones for better portability, migration tool coming soon
3
  * changed: ExactDN defaults to crop when explicit dimensions are given to image_downsize(), revert to scaling with EXACTDN_IMAGE_DOWNSIZE_SCALE
1
+ = 4.5.2 =
2
+ * added: automatic migration to move image paths from absolute to relative
3
+ * changed: default quality for PNG to JPG did not match WordPress default
4
+ * fixed: legacy absolute paths not matched during bulk scanner when relative matching is enabled
5
+ * fixed: PNG to JPG auto-convert produces larger JPG images in some cases
6
+
7
  = 4.5.1 =
8
  * changed: optimization results are tracked by relative urls instead of absolute ones for better portability, migration tool coming soon
9
  * changed: ExactDN defaults to crop when explicit dimensions are given to image_downsize(), revert to scaling with EXACTDN_IMAGE_DOWNSIZE_SCALE
classes/class-ewww-image.php CHANGED
@@ -173,12 +173,12 @@ class EWWW_Image {
173
  ewwwio_debug_message( print_r( $new_image, true ) );
174
  }
175
  $this->id = $new_image['id'];
176
- $this->file = ewww_image_optimizer_relative_path_replace( $new_image['path'] );
177
  $this->attachment_id = $new_image['attachment_id'];
178
  $this->opt_size = $new_image['image_size'];
179
  $this->orig_size = $new_image['orig_size'];
180
  $this->resize = $new_image['resize'];
181
- $this->converted = ewww_image_optimizer_relative_path_replace( $new_image['converted'] );
182
  $this->gallery = ( empty( $gallery ) ? $new_image['gallery'] : $gallery );
183
  $this->backup = $new_image['backup'];
184
  $this->record = $new_image;
@@ -251,7 +251,7 @@ class EWWW_Image {
251
  }
252
  /* ewwwio_debug_message( 'about to process db results' ); */
253
  foreach ( $sizes_queried as $size_queried ) {
254
- $size_queried['path'] = ewww_image_optimizer_relative_path_replace( $size_queried['path'] );
255
 
256
  $sizes[ $size_queried['resize'] ] = $size_queried;
257
  // Convert here.
@@ -418,8 +418,8 @@ class EWWW_Image {
418
  if ( empty( $size_queried['converted'] ) ) {
419
  continue;
420
  }
421
- $size_queried['path'] = ewww_image_optimizer_relative_path_replace( $size_queried['path'] );
422
- $size_queried['converted'] = ewww_image_optimizer_relative_path_replace( $size_queried['converted'] );
423
 
424
  $new_name = ( empty( $size_queried['converted'] ) ? '' : $size_queried['converted'] );
425
  if ( $new_name && is_file( $size_queried['path'] ) && is_file( $new_name ) ) {
@@ -478,9 +478,10 @@ class EWWW_Image {
478
  *
479
  * @param string $file The name of the file to convert.
480
  * @param bool $replace_url Default true. Run function to update database with new url.
 
481
  * @return string The name of the new file.
482
  */
483
- public function convert( $file, $replace_url = true ) {
484
  ewwwio_debug_message( '<b>' . __FUNCTION__ . '()</b>' );
485
  if ( empty( $file ) ) {
486
  ewwwio_debug_message( 'no file provided to convert' );
@@ -538,13 +539,20 @@ class EWWW_Image {
538
  }
539
  ewwwio_debug_message( "converted PNG size: $png_size" );
540
  // If the PNG exists, and we didn't end up with an empty file.
541
- if ( $png_size && is_file( $newfile ) && ewww_image_optimizer_mimetype( $newfile, 'i' ) == 'image/png' ) {
542
  ewwwio_debug_message( 'JPG to PNG successful' );
543
  // Check to see if the user wants the originals deleted.
544
  if ( ewww_image_optimizer_get_option( 'ewww_image_optimizer_delete_originals' ) == true ) {
545
  // Delete the original JPG.
546
  unlink( $file );
547
  }
 
 
 
 
 
 
 
548
  } else {
549
  ewwwio_debug_message( 'converted PNG is no good' );
550
  if ( is_file( $newfile ) ) {
@@ -571,9 +579,8 @@ class EWWW_Image {
571
  }
572
  // If the user manually set the JPG quality.
573
  $quality = ewww_image_optimizer_jpg_quality();
574
- if ( empty( $quality ) ) {
575
- $quality = '92';
576
- }
577
  $magick_background = ewww_image_optimizer_jpg_background();
578
  if ( empty( $magick_background ) ) {
579
  $magick_background = '000000';
@@ -637,13 +644,20 @@ class EWWW_Image {
637
  }
638
  ewwwio_debug_message( "converted JPG size: $jpg_size" );
639
  // If the new JPG is smaller than the original PNG.
640
- if ( $jpg_size && is_file( $newfile ) && ewww_image_optimizer_mimetype( $newfile, 'i' ) == 'image/jpeg' ) {
641
  ewwwio_debug_message( 'JPG to PNG successful' );
642
  // If the user wants originals delted after a conversion.
643
  if ( ewww_image_optimizer_get_option( 'ewww_image_optimizer_delete_originals' ) == true ) {
644
  // Delete the original PNG.
645
  unlink( $file );
646
  }
 
 
 
 
 
 
 
647
  } else {
648
  if ( is_file( $newfile ) ) {
649
  // Otherwise delete the new JPG.
@@ -686,13 +700,20 @@ class EWWW_Image {
686
  }
687
  ewwwio_debug_message( "converted PNG size: $png_size" );
688
  // If the PNG exists, and we didn't end up with an empty file.
689
- if ( $png_size && is_file( $newfile ) && ewww_image_optimizer_mimetype( $newfile, 'i' ) == 'image/png' ) {
690
  ewwwio_debug_message( 'GIF to PNG successful' );
691
  // Check to see if the user wants the originals deleted.
692
  if ( ewww_image_optimizer_get_option( 'ewww_image_optimizer_delete_originals' ) == true ) {
693
  // Delete the original JPG.
694
  unlink( $file );
695
  }
 
 
 
 
 
 
 
696
  } else {
697
  ewwwio_debug_message( 'converted PNG is no good' );
698
  if ( is_file( $newfile ) ) {
@@ -839,8 +860,8 @@ class EWWW_Image {
839
  $ewwwdb->insert(
840
  $ewwwdb->ewwwio_images,
841
  array(
842
- 'path' => ewww_image_optimizer_relative_path_remove( $new_path ),
843
- 'converted' => ewww_image_optimizer_relative_path_remove( $path ),
844
  'orig_size' => filesize( $new_path ),
845
  'attachment_id' => $this->attachment_id,
846
  'results' => __( 'No savings', 'ewww-image-optimizer' ),
@@ -854,8 +875,8 @@ class EWWW_Image {
854
  $ewwwdb->update(
855
  $ewwwdb->ewwwio_images,
856
  array(
857
- 'path' => ewww_image_optimizer_relative_path_remove( $new_path ),
858
- 'converted' => ewww_image_optimizer_relative_path_remove( $path ),
859
  'results' => ewww_image_optimizer_image_results( $image_record['orig_size'], filesize( $new_path ) ),
860
  'updates' => 0,
861
  'trace' => '',
@@ -898,7 +919,7 @@ class EWWW_Image {
898
  $ewwwdb->update(
899
  $ewwwdb->ewwwio_images,
900
  array(
901
- 'path' => ewww_image_optimizer_relative_path_remove( $new_path ),
902
  'converted' => '',
903
  'image_size' => 0,
904
  'results' => __( 'Original Restored', 'ewww-image-optimizer' ),
173
  ewwwio_debug_message( print_r( $new_image, true ) );
174
  }
175
  $this->id = $new_image['id'];
176
+ $this->file = ewww_image_optimizer_absolutize_path( $new_image['path'] );
177
  $this->attachment_id = $new_image['attachment_id'];
178
  $this->opt_size = $new_image['image_size'];
179
  $this->orig_size = $new_image['orig_size'];
180
  $this->resize = $new_image['resize'];
181
+ $this->converted = ewww_image_optimizer_absolutize_path( $new_image['converted'] );
182
  $this->gallery = ( empty( $gallery ) ? $new_image['gallery'] : $gallery );
183
  $this->backup = $new_image['backup'];
184
  $this->record = $new_image;
251
  }
252
  /* ewwwio_debug_message( 'about to process db results' ); */
253
  foreach ( $sizes_queried as $size_queried ) {
254
+ $size_queried['path'] = ewww_image_optimizer_absolutize_path( $size_queried['path'] );
255
 
256
  $sizes[ $size_queried['resize'] ] = $size_queried;
257
  // Convert here.
418
  if ( empty( $size_queried['converted'] ) ) {
419
  continue;
420
  }
421
+ $size_queried['path'] = ewww_image_optimizer_absolutize_path( $size_queried['path'] );
422
+ $size_queried['converted'] = ewww_image_optimizer_absolutize_path( $size_queried['converted'] );
423
 
424
  $new_name = ( empty( $size_queried['converted'] ) ? '' : $size_queried['converted'] );
425
  if ( $new_name && is_file( $size_queried['path'] ) && is_file( $new_name ) ) {
478
  *
479
  * @param string $file The name of the file to convert.
480
  * @param bool $replace_url Default true. Run function to update database with new url.
481
+ * @param bool $check_size Default false. Whether the converted filesize be compared to the original.
482
  * @return string The name of the new file.
483
  */
484
+ public function convert( $file, $replace_url = true, $check_size = false ) {
485
  ewwwio_debug_message( '<b>' . __FUNCTION__ . '()</b>' );
486
  if ( empty( $file ) ) {
487
  ewwwio_debug_message( 'no file provided to convert' );
539
  }
540
  ewwwio_debug_message( "converted PNG size: $png_size" );
541
  // If the PNG exists, and we didn't end up with an empty file.
542
+ if ( ! $check_size && $png_size && is_file( $newfile ) && ewww_image_optimizer_mimetype( $newfile, 'i' ) == 'image/png' ) {
543
  ewwwio_debug_message( 'JPG to PNG successful' );
544
  // Check to see if the user wants the originals deleted.
545
  if ( ewww_image_optimizer_get_option( 'ewww_image_optimizer_delete_originals' ) == true ) {
546
  // Delete the original JPG.
547
  unlink( $file );
548
  }
549
+ } elseif ( $check_size && is_file( $newfile ) && $png_size < ewww_image_optimizer_filesize( $file ) && ewww_image_optimizer_mimetype( $newfile, 'i' ) == 'image/png' ) {
550
+ ewwwio_debug_message( 'JPG to PNG successful, after comparing size' );
551
+ // Check to see if the user wants the originals deleted.
552
+ if ( ewww_image_optimizer_get_option( 'ewww_image_optimizer_delete_originals' ) == true ) {
553
+ // Delete the original JPG.
554
+ unlink( $file );
555
+ }
556
  } else {
557
  ewwwio_debug_message( 'converted PNG is no good' );
558
  if ( is_file( $newfile ) ) {
579
  }
580
  // If the user manually set the JPG quality.
581
  $quality = ewww_image_optimizer_jpg_quality();
582
+ $quality = $quality ? $quality : '82';
583
+
 
584
  $magick_background = ewww_image_optimizer_jpg_background();
585
  if ( empty( $magick_background ) ) {
586
  $magick_background = '000000';
644
  }
645
  ewwwio_debug_message( "converted JPG size: $jpg_size" );
646
  // If the new JPG is smaller than the original PNG.
647
+ if ( ! $check_size && $jpg_size && is_file( $newfile ) && ewww_image_optimizer_mimetype( $newfile, 'i' ) == 'image/jpeg' ) {
648
  ewwwio_debug_message( 'JPG to PNG successful' );
649
  // If the user wants originals delted after a conversion.
650
  if ( ewww_image_optimizer_get_option( 'ewww_image_optimizer_delete_originals' ) == true ) {
651
  // Delete the original PNG.
652
  unlink( $file );
653
  }
654
+ } elseif ( $check_size && is_file( $newfile ) && $jpg_size < ewww_image_optimizer_filesize( $file ) && ewww_image_optimizer_mimetype( $newfile, 'i' ) == 'image/jpeg' ) {
655
+ ewwwio_debug_message( 'PNG to JPG successful, after comparing size' );
656
+ // If the user wants originals delted after a conversion.
657
+ if ( ewww_image_optimizer_get_option( 'ewww_image_optimizer_delete_originals' ) == true ) {
658
+ // Delete the original PNG.
659
+ unlink( $file );
660
+ }
661
  } else {
662
  if ( is_file( $newfile ) ) {
663
  // Otherwise delete the new JPG.
700
  }
701
  ewwwio_debug_message( "converted PNG size: $png_size" );
702
  // If the PNG exists, and we didn't end up with an empty file.
703
+ if ( ! $check_size && $png_size && is_file( $newfile ) && ewww_image_optimizer_mimetype( $newfile, 'i' ) == 'image/png' ) {
704
  ewwwio_debug_message( 'GIF to PNG successful' );
705
  // Check to see if the user wants the originals deleted.
706
  if ( ewww_image_optimizer_get_option( 'ewww_image_optimizer_delete_originals' ) == true ) {
707
  // Delete the original JPG.
708
  unlink( $file );
709
  }
710
+ } elseif ( $check_size && is_file( $newfile ) && $png_size < ewww_image_optimizer_filesize( $file ) && ewww_image_optimizer_mimetype( $newfile, 'i' ) == 'image/png' ) {
711
+ ewwwio_debug_message( 'GIF to PNG successful, after comparing size' );
712
+ // Check to see if the user wants the originals deleted.
713
+ if ( ewww_image_optimizer_get_option( 'ewww_image_optimizer_delete_originals' ) == true ) {
714
+ // Delete the original JPG.
715
+ unlink( $file );
716
+ }
717
  } else {
718
  ewwwio_debug_message( 'converted PNG is no good' );
719
  if ( is_file( $newfile ) ) {
860
  $ewwwdb->insert(
861
  $ewwwdb->ewwwio_images,
862
  array(
863
+ 'path' => ewww_image_optimizer_relativize_path( $new_path ),
864
+ 'converted' => ewww_image_optimizer_relativize_path( $path ),
865
  'orig_size' => filesize( $new_path ),
866
  'attachment_id' => $this->attachment_id,
867
  'results' => __( 'No savings', 'ewww-image-optimizer' ),
875
  $ewwwdb->update(
876
  $ewwwdb->ewwwio_images,
877
  array(
878
+ 'path' => ewww_image_optimizer_relativize_path( $new_path ),
879
+ 'converted' => ewww_image_optimizer_relativize_path( $path ),
880
  'results' => ewww_image_optimizer_image_results( $image_record['orig_size'], filesize( $new_path ) ),
881
  'updates' => 0,
882
  'trace' => '',
919
  $ewwwdb->update(
920
  $ewwwdb->ewwwio_images,
921
  array(
922
+ 'path' => ewww_image_optimizer_relativize_path( $new_path ),
923
  'converted' => '',
924
  'image_size' => 0,
925
  'results' => __( 'Original Restored', 'ewww-image-optimizer' ),
classes/class-ewwwio-relative-migration.php ADDED
@@ -0,0 +1,187 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Class file for EWWWIO_Relative_Migration
4
+ *
5
+ * Performs the migration from storing absolute paths to using relative paths in the ewwwio_images table.
6
+ *
7
+ * @link https://ewww.io
8
+ * @package EWWW_Image_Optimizer
9
+ * @since 4.5.2
10
+ */
11
+
12
+ if ( ! defined( 'ABSPATH' ) ) {
13
+ exit;
14
+ }
15
+
16
+ /**
17
+ * Migrates absolute paths to relative paths (once).
18
+ */
19
+ class EWWWIO_Relative_Migration {
20
+
21
+ /**
22
+ * The offset/position in the database.
23
+ *
24
+ * @var int $id
25
+ */
26
+ private $offset = 0;
27
+
28
+ /**
29
+ * The time when we started processing.
30
+ *
31
+ * @var int $started
32
+ */
33
+ private $started;
34
+
35
+ /**
36
+ * Sets up the the migration.
37
+ */
38
+ function __construct() {
39
+ if ( 'done' === get_option( 'ewww_image_optimizer_relative_migration_status' ) ) {
40
+ return;
41
+ }
42
+ if ( ! get_option( 'ewww_image_optimizer_relative_migration_status' ) ) {
43
+ update_option( 'ewww_image_optimizer_relative_migration_status', 'started' );
44
+ }
45
+ $this->maybe_schedule();
46
+ }
47
+
48
+ /**
49
+ * Retrieves a batch of records based on the current offset.
50
+ */
51
+ private function get_records() {
52
+ ewwwio_debug_message( '<b>' . __FUNCTION__ . '()</b>' );
53
+ global $wpdb;
54
+ if ( strpos( $wpdb->charset, 'utf8' ) === false ) {
55
+ ewww_image_optimizer_db_init();
56
+ global $ewwwdb;
57
+ } else {
58
+ $ewwwdb = $wpdb;
59
+ }
60
+ $query = "SELECT id,path,updated FROM $ewwwdb->ewwwio_images WHERE pending=0 AND image_size > 0 ORDER BY id DESC LIMIT $this->offset,500";
61
+ $records = $ewwwdb->get_results( $query, ARRAY_A );
62
+
63
+ $this->offset += 500;
64
+ if ( is_array( $records ) ) {
65
+ return $records;
66
+ }
67
+ return array();
68
+ }
69
+
70
+ /**
71
+ * Called via wp_cron to initiate the migration effort.
72
+ */
73
+ public function migrate() {
74
+ ewwwio_debug_message( '<b>' . __FUNCTION__ . '()</b>' );
75
+ $this->started = time();
76
+ $this->offset = (int) get_option( 'ewww_image_optimizer_relative_migration_offset' );
77
+ $records = $this->get_records();
78
+ ewwwio_debug_message( 'starting at ' . date( 'Y-m-d H:i:s', $this->started ) . " with offset $this->offset" );
79
+ while ( ! empty( $records ) ) {
80
+ foreach ( $records as $record ) {
81
+ if ( $this->already_migrated( $record['path'] ) ) {
82
+ ewwwio_debug_message( 'already migrated' );
83
+ continue;
84
+ }
85
+ // Relativize the path, and store it back in the db.
86
+ $relative_path = ewww_image_optimizer_relativize_path( $record['path'] );
87
+ if ( $record['path'] !== $relative_path ) {
88
+ $record['path'] = $relative_path;
89
+ $this->update_relative_record( $record );
90
+ }
91
+ }
92
+ if ( time() - $this->started > 20 ) {
93
+ update_option( 'ewww_image_optimizer_relative_migration_offset', $this->offset, false );
94
+ return;
95
+ }
96
+ $records = $this->get_records();
97
+ }
98
+ $this->unschedule();
99
+ update_option( 'ewww_image_optimizer_relative_migration_status', 'done' );
100
+ delete_option( 'ewww_image_optimizer_relative_migration_offset' );
101
+ }
102
+
103
+ /**
104
+ * Checks to see if the record already has been migrated.
105
+ *
106
+ * @param string $path Path of file as retrieved from database.
107
+ */
108
+ private function already_migrated( $path ) {
109
+ if ( strpos( $path, 'EWWW_IMAGE_OPTIMIZER_RELATIVE_FOLDER' ) === 0 ) {
110
+ return true;
111
+ }
112
+ if ( strpos( $path, 'ABSPATH' ) === 0 ) {
113
+ return true;
114
+ }
115
+ if ( strpos( $path, 'WP_CONTENT_DIR' ) === 0 ) {
116
+ return true;
117
+ }
118
+ return false;
119
+ }
120
+
121
+ /**
122
+ * Updates the db record with the relativized path.
123
+ *
124
+ * @param array $record Includes a relative path, the ID, and the updated timestamp.
125
+ */
126
+ private function update_relative_record( $record ) {
127
+ ewwwio_debug_message( '<b>' . __FUNCTION__ . '()</b>' );
128
+ global $wpdb;
129
+ if ( strpos( $wpdb->charset, 'utf8' ) === false ) {
130
+ ewww_image_optimizer_db_init();
131
+ global $ewwwdb;
132
+ } else {
133
+ $ewwwdb = $wpdb;
134
+ }
135
+ $ewwwdb->update(
136
+ $ewwwdb->ewwwio_images,
137
+ array(
138
+ 'path' => $record['path'],
139
+ 'updated' => $record['updated'],
140
+ ),
141
+ array(
142
+ 'id' => $record['id'],
143
+ )
144
+ );
145
+ }
146
+
147
+ /**
148
+ * Schedule the migration.
149
+ */
150
+ private function maybe_schedule() {
151
+ ewwwio_debug_message( '<b>' . __FUNCTION__ . '()</b>' );
152
+ // Create 5 minute wp_cron schedule.
153
+ add_filter( 'cron_schedules', array( $this, 'add_migration_schedule' ) );
154
+ add_action( 'ewww_image_optimizer_relative_migration', array( $this, 'migrate' ) );
155
+ // Schedule migration function.
156
+ if ( ! wp_next_scheduled( 'ewww_image_optimizer_relative_migration' ) ) {
157
+ ewwwio_debug_message( 'scheduling migration' );
158
+ wp_schedule_event( time(), 'ewwwio_relative_migration_interval', 'ewww_image_optimizer_relative_migration' );
159
+ }
160
+ }
161
+ /**
162
+ * Clean up the scheduled event.
163
+ */
164
+ private function unschedule() {
165
+ ewwwio_debug_message( '<b>' . __FUNCTION__ . '()</b>' );
166
+ $timestamp = wp_next_scheduled( 'ewww_image_optimizer_relative_migration' );
167
+ if ( $timestamp ) {
168
+ wp_unschedule_event( $timestamp, 'ewww_image_optimizer_relative_migration' );
169
+ }
170
+ }
171
+
172
+
173
+ /**
174
+ * Adds a custom cron schedule: every 5 minutes.
175
+ *
176
+ * @param array $schedules An array of custom cron schedules.
177
+ */
178
+ public function add_migration_schedule( $schedules ) {
179
+ ewwwio_debug_message( '<b>' . __FUNCTION__ . '()</b>' );
180
+ $schedules['ewwwio_relative_migration_interval'] = array(
181
+ 'interval' => MINUTE_IN_SECONDS * 5,
182
+ 'display' => 'Every 5 Minutes',
183
+ );
184
+ return $schedules;
185
+ }
186
+ }
187
+ new EWWWIO_Relative_Migration();
common.php CHANGED
@@ -23,7 +23,7 @@ if ( ! defined( 'ABSPATH' ) ) {
23
  exit;
24
  }
25
 
26
- define( 'EWWW_IMAGE_OPTIMIZER_VERSION', '451.0' );
27
 
28
  // Initialize a couple globals.
29
  $ewww_debug = '';
@@ -218,6 +218,9 @@ if ( ewww_image_optimizer_get_option( 'ewww_image_optimizer_webp_for_cdn' ) ) {
218
  if ( defined( 'WP_CLI' ) && WP_CLI ) {
219
  require_once( EWWW_IMAGE_OPTIMIZER_PLUGIN_PATH . 'classes/class-ewwwio-cli.php' );
220
  }
 
 
 
221
 
222
  /**
223
  * Skips optimization when a file is within EWWW IO's own folder.
@@ -1360,6 +1363,7 @@ function ewww_image_optimizer_notice_media_listmode() {
1360
  }
1361
  }
1362
  }
 
1363
  /**
1364
  * Alert the user when 5 images have been re-optimized more than 10 times.
1365
  *
@@ -1553,7 +1557,7 @@ function ewww_image_optimizer_path_renamed( $post, $old_filepath, $new_filepath
1553
  $ewwwdb->update(
1554
  $ewwwdb->ewwwio_images,
1555
  array(
1556
- 'path' => ewww_image_optimizer_relative_path_remove( $new_filepath ),
1557
  ),
1558
  array(
1559
  'id' => $optimized_query['id'],
@@ -1838,7 +1842,7 @@ function ewww_image_optimizer_auto() {
1838
  ewwwio_debug_message( "$nonce is fine, compared to $current_nonce" );
1839
  }
1840
  if ( ! empty( $attachment['path'] ) ) {
1841
- $attachment['path'] = ewww_image_optimizer_relative_path_replace( $attachment['path'] );
1842
  }
1843
  ewww_image_optimizer_aux_images_loop( $attachment, true );
1844
  if ( ! empty( $delay ) && ewww_image_optimizer_function_exists( 'sleep' ) ) {
@@ -2021,7 +2025,7 @@ function ewww_image_optimizer_retina( $id, $retina_path ) {
2021
  $ewwwdb->update(
2022
  $ewwwdb->ewwwio_images,
2023
  array(
2024
- 'path' => ewww_image_optimizer_relative_path_remove( $retina_path ),
2025
  'attachment_id' => $id,
2026
  'gallery' => 'media',
2027
  ),
@@ -2226,6 +2230,26 @@ function ewww_image_optimizer_gmagick_support() {
2226
  return false;
2227
  }
2228
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2229
  /**
2230
  * Sanitize the list of disabled resizes.
2231
  *
@@ -2396,7 +2420,7 @@ function ewww_image_optimizer_escapeshellarg( $arg ) {
2396
  */
2397
  function ewww_image_optimizer_jpg_background( $background = null ) {
2398
  ewwwio_debug_message( '<b>' . __FUNCTION__ . '()</b>' );
2399
- if ( null === $background ) {
2400
  // Retrieve the user-supplied value for jpg background color.
2401
  $background = ewww_image_optimizer_get_option( 'ewww_image_optimizer_jpg_background' );
2402
  }
@@ -2426,7 +2450,7 @@ function ewww_image_optimizer_jpg_background( $background = null ) {
2426
  */
2427
  function ewww_image_optimizer_jpg_quality( $quality = null ) {
2428
  ewwwio_debug_message( '<b>' . __FUNCTION__ . '()</b>' );
2429
- if ( null === $quality ) {
2430
  // Retrieve the user-supplied value for jpg quality.
2431
  $quality = ewww_image_optimizer_get_option( 'ewww_image_optimizer_jpg_quality' );
2432
  }
@@ -2446,26 +2470,6 @@ function ewww_image_optimizer_jpg_quality( $quality = null ) {
2446
  }
2447
  }
2448
 
2449
- /**
2450
- * Filter the filename past any folders the user chose to ignore.
2451
- *
2452
- * @param bool $bypass True to skip optimization, defaults to false.
2453
- * @param string $filename The file about to be optimized.
2454
- * @return bool True if the file matches any folders to ignore.
2455
- */
2456
- function ewww_image_optimizer_ignore_file( $bypass, $filename ) {
2457
- $ignore_folders = ewww_image_optimizer_get_option( 'ewww_image_optimizer_exclude_paths' );
2458
- if ( ! ewww_image_optimizer_iterable( $ignore_folders ) ) {
2459
- return $bypass;
2460
- }
2461
- foreach ( $ignore_folders as $ignore_folder ) {
2462
- if ( strpos( $filename, $ignore_folder ) !== false ) {
2463
- return true;
2464
- }
2465
- }
2466
- return $bypass;
2467
- }
2468
-
2469
  /**
2470
  * Overrides the default JPG quality for WordPress image editing operations.
2471
  *
@@ -2632,7 +2636,7 @@ function ewww_image_optimizer_restore_from_meta_data( $meta, $id ) {
2632
  return $meta;
2633
  }
2634
  }
2635
- $ewww_image = new EWWW_Image( $id, 'media', ewww_image_optimizer_relative_path_replace( $db_image['path'] ) );
2636
  return $ewww_image->restore_with_meta( $meta );
2637
  }
2638
 
@@ -2657,7 +2661,7 @@ function ewww_image_optimizer_cloud_restore_from_meta_data( $id, $gallery = 'med
2657
  $images = $ewwwdb->get_results( "SELECT id,path,backup FROM $ewwwdb->ewwwio_images WHERE attachment_id = $id AND gallery = '$gallery'", ARRAY_A );
2658
  foreach ( $images as $image ) {
2659
  if ( ! empty( $image['path'] ) ) {
2660
- $image['path'] = ewww_image_optimizer_relative_path_replace( $image['path'] );
2661
  }
2662
  ewww_image_optimizer_cloud_restore_single_image( $image );
2663
  }
@@ -2717,7 +2721,7 @@ function ewww_image_optimizer_cloud_restore_single_image( $image ) {
2717
  $image = $ewwwdb->get_row( "SELECT id,path,backup FROM $ewwwdb->ewwwio_images WHERE id = $image", ARRAY_A );
2718
  }
2719
  if ( ! empty( $image['path'] ) ) {
2720
- $image['path'] = ewww_image_optimizer_relative_path_replace( $image['path'] );
2721
  }
2722
  $api_key = ewww_image_optimizer_get_option( 'ewww_image_optimizer_cloud_key' );
2723
  $domain = parse_url( get_site_url(), PHP_URL_HOST );
@@ -2794,7 +2798,7 @@ function ewww_image_optimizer_delete( $id ) {
2794
  if ( ewww_image_optimizer_iterable( $optimized_images ) ) {
2795
  foreach ( $optimized_images as $image ) {
2796
  if ( ! empty( $image['path'] ) ) {
2797
- $image['path'] = ewww_image_optimizer_relative_path_replace( $image['path'] );
2798
  }
2799
  if ( strpos( $image['path'], WP_CONTENT_DIR ) === false ) {
2800
  continue;
@@ -2806,7 +2810,7 @@ function ewww_image_optimizer_delete( $id ) {
2806
  }
2807
  }
2808
  if ( ! empty( $image['converted'] ) ) {
2809
- $image['converted'] = ewww_image_optimizer_relative_path_replace( $image['converted'] );
2810
  }
2811
  if ( ! empty( $image['converted'] ) && is_file( $image['converted'] ) ) {
2812
  unlink( $image['converted'] );
@@ -2842,12 +2846,12 @@ function ewww_image_optimizer_delete( $id ) {
2842
  // If the original file still exists and no posts contain links to the image.
2843
  if ( is_file( $file_path ) && empty( $rows ) ) {
2844
  unlink( $file_path );
2845
- $ewwwdb->delete( $ewwwdb->ewwwio_images, array( 'path' => ewww_image_optimizer_relative_path_remove( $file_path ) ) );
2846
  }
2847
  }
2848
  // Remove the regular image from the ewwwio_images tables.
2849
  list( $file_path, $upload_path ) = ewww_image_optimizer_attachment_path( $meta, $id );
2850
- $ewwwdb->delete( $ewwwdb->ewwwio_images, array( 'path' => ewww_image_optimizer_relative_path_remove( $file_path ) ) );
2851
  // Resized versions, so we can continue.
2852
  if ( isset( $meta['sizes'] ) && ewww_image_optimizer_iterable( $meta['sizes'] ) ) {
2853
  // One way or another, $file_path is now set, and we can get the base folder name.
@@ -2862,7 +2866,7 @@ function ewww_image_optimizer_delete( $id ) {
2862
  if ( is_file( $webpfileold ) ) {
2863
  unlink( $webpfileold );
2864
  }
2865
- $ewwwdb->delete( $ewwwdb->ewwwio_images, array( 'path' => ewww_image_optimizer_relative_path_remove( $base_dir . $data['file'] ) ) );
2866
  // If the original resize is set, and still exists.
2867
  if ( ! empty( $data['orig_file'] ) && is_file( $base_dir . $data['orig_file'] ) ) {
2868
  unset( $srows );
@@ -2874,7 +2878,7 @@ function ewww_image_optimizer_delete( $id ) {
2874
  // If there are no posts containing links to the original, delete it.
2875
  if ( empty( $srows ) ) {
2876
  unlink( $base_dir . $data['orig_file'] );
2877
- $ewwwdb->delete( $ewwwdb->ewwwio_images, array( 'path' => ewww_image_optimizer_relative_path_remove( $base_dir . $data['orig_file'] ) ) );
2878
  }
2879
  }
2880
  }
@@ -3842,7 +3846,7 @@ function ewww_image_optimizer_update_table( $attachment, $opt_size, $orig_size,
3842
  $results_msg = ewww_image_optimizer_image_results( $orig_size, $opt_size, $prev_string );
3843
 
3844
  $updates = array(
3845
- 'path' => ewww_image_optimizer_relative_path_remove( $attachment ),
3846
  'converted' => $converted,
3847
  'level' => 0,
3848
  'image_size' => $opt_size,
@@ -4025,7 +4029,7 @@ function ewww_image_optimizer_aux_images_loop( $attachment = null, $auto = false
4025
  $attachment = $attachment['path'];
4026
  }
4027
  if ( $attachment ) {
4028
- $attachment = ewww_image_optimizer_relative_path_replace( $attachment );
4029
  }
4030
  // Do the optimization for the current image.
4031
  $results = ewww_image_optimizer( $attachment );
@@ -4070,7 +4074,7 @@ function ewww_image_optimizer_aux_images_loop( $attachment = null, $auto = false
4070
  global $ewww_debug;
4071
  $output['results'] .= '<div style="background-color:#ffff99;">' . $ewww_debug . '</div>';
4072
  }
4073
- $next_file = ewww_image_optimizer_relative_path_replace( $wpdb->get_var( "SELECT path FROM $wpdb->ewwwio_images WHERE pending=1 LIMIT 1" ) );
4074
  if ( ! empty( $next_file ) ) {
4075
  $loading_image = plugins_url( '/images/wpspin.gif', __FILE__ );
4076
  $output['next_file'] = '<p>' . esc_html__( 'Optimizing', 'ewww-image-optimizer' ) . ' <b>' . esc_html( $next_file ) . "</b>&nbsp;<img src='$loading_image' alt='loading'/></p>";
@@ -4374,7 +4378,7 @@ function ewww_image_optimizer_update_table_as3cf( $local_path, $s3_path ) {
4374
  $ewwwdb->update(
4375
  $ewwwdb->ewwwio_images,
4376
  array(
4377
- 'path' => ewww_image_optimizer_relative_path_remove( $local_path ),
4378
  ),
4379
  array(
4380
  'id' => $s3_image['id'],
@@ -4556,7 +4560,8 @@ function ewww_image_optimizer_autoconvert( $file ) {
4556
  return;
4557
  }
4558
  $ewww_image = new EWWW_Image( 0, '', $file );
4559
- return $ewww_image->convert( $file, false );
 
4560
  }
4561
 
4562
  /**
@@ -4771,11 +4776,11 @@ function ewww_image_optimizer_resize_upload( $file ) {
4771
  $tmp_exists = $ewwwdb->update(
4772
  $ewwwdb->ewwwio_images,
4773
  array(
4774
- 'path' => ewww_image_optimizer_relative_path_remove( $file ),
4775
  'orig_size' => $orig_size,
4776
  ),
4777
  array(
4778
- 'path' => ewww_image_optimizer_relative_path_remove( $new_file ),
4779
  )
4780
  );
4781
  // If the tmp file didn't get optimized (and it shouldn't), then just insert a dummy record to be updated shortly.
@@ -4783,7 +4788,7 @@ function ewww_image_optimizer_resize_upload( $file ) {
4783
  $ewwwdb->insert(
4784
  $ewwwdb->ewwwio_images,
4785
  array(
4786
- 'path' => ewww_image_optimizer_relative_path_remove( $file ),
4787
  'orig_size' => $orig_size,
4788
  )
4789
  );
@@ -4853,12 +4858,17 @@ function ewww_image_optimizer_find_already_optimized( $attachment ) {
4853
  } else {
4854
  $ewwwdb = $wpdb;
4855
  }
4856
- $maybe_return_image = false;
4857
- $query = $ewwwdb->prepare( "SELECT * FROM $ewwwdb->ewwwio_images WHERE path = %s", ewww_image_optimizer_relative_path_remove( $attachment ) );
4858
- $optimized_query = $ewwwdb->get_results( $query, ARRAY_A );
 
 
 
 
 
4859
  if ( ewww_image_optimizer_iterable( $optimized_query ) ) {
4860
  foreach ( $optimized_query as $image ) {
4861
- $image['path'] = ewww_image_optimizer_relative_path_replace( $image['path'] );
4862
  if ( $image['path'] != $attachment ) {
4863
  ewwwio_debug_message( "{$image['path']} does not match $attachment, continuing our search" );
4864
  } elseif ( ! $maybe_return_image ) {
@@ -5191,7 +5201,7 @@ function ewww_image_optimizer_resize_from_meta_data( $meta, $id = null, $log = t
5191
  $ewwwdb->update(
5192
  $ewwwdb->ewwwio_images,
5193
  array(
5194
- 'path' => ewww_image_optimizer_relative_path_remove( $file_path ),
5195
  'attachment_id' => $id,
5196
  'resize' => 'full',
5197
  'gallery' => 'media',
@@ -5350,7 +5360,7 @@ function ewww_image_optimizer_resize_from_meta_data( $meta, $id = null, $log = t
5350
  $ewwwdb->update(
5351
  $ewwwdb->ewwwio_images,
5352
  array(
5353
- 'path' => ewww_image_optimizer_relative_path_remove( $ims_path ),
5354
  ),
5355
  array(
5356
  'id' => $already_optimized['id'],
@@ -5871,7 +5881,7 @@ function ewww_image_optimizer_attachment_path( $meta, $id, $file = '', $refresh_
5871
  * @param string $file The filename to mangle.
5872
  * @return string The filename with parent folders replaced by a constant name.
5873
  */
5874
- function ewww_image_optimizer_relative_path_remove( $file ) {
5875
  if ( ! defined( 'EWWW_IMAGE_OPTIMIZER_RELATIVE' ) || ! EWWW_IMAGE_OPTIMIZER_RELATIVE ) {
5876
  return $file;
5877
  }
@@ -5896,12 +5906,12 @@ function ewww_image_optimizer_relative_path_remove( $file ) {
5896
  *
5897
  * Replaces the literal strings 'ABSPATH', 'WP_CONTENT_DIR', or
5898
  * 'EWWW_IMAGE_OPTIMIZER_RELATIVE_FOLDER' with the actual value of the constant contained within
5899
- * the file path.string name of the applicable constant.
5900
  *
5901
  * @param string $file The filename to parse.
5902
  * @return string The full filename with parent folders reinserted.
5903
  */
5904
- function ewww_image_optimizer_relative_path_replace( $file ) {
5905
  if ( ! defined( 'EWWW_IMAGE_OPTIMIZER_RELATIVE' ) ) {
5906
  return $file;
5907
  }
@@ -8369,7 +8379,7 @@ function ewww_image_optimizer_debug_log() {
8369
  if ( ! empty( $ewww_debug ) && ewww_image_optimizer_get_option( 'ewww_image_optimizer_debug' ) ) {
8370
  $memory_limit = ewwwio_memory_limit();
8371
  clearstatcache();
8372
- $timestamp = date( 'y-m-d h:i:s.u' ) . "\n";
8373
  if ( ! file_exists( EWWW_IMAGE_OPTIMIZER_PLUGIN_PATH . 'debug.log' ) ) {
8374
  touch( EWWW_IMAGE_OPTIMIZER_PLUGIN_PATH . 'debug.log' );
8375
  } else {
23
  exit;
24
  }
25
 
26
+ define( 'EWWW_IMAGE_OPTIMIZER_VERSION', '452.0' );
27
 
28
  // Initialize a couple globals.
29
  $ewww_debug = '';
218
  if ( defined( 'WP_CLI' ) && WP_CLI ) {
219
  require_once( EWWW_IMAGE_OPTIMIZER_PLUGIN_PATH . 'classes/class-ewwwio-cli.php' );
220
  }
221
+ if ( 'done' !== get_option( 'ewww_image_optimizer_relative_migration_status' ) ) {
222
+ require_once( EWWW_IMAGE_OPTIMIZER_PLUGIN_PATH . 'classes/class-ewwwio-relative-migration.php' );
223
+ }
224
 
225
  /**
226
  * Skips optimization when a file is within EWWW IO's own folder.
1363
  }
1364
  }
1365
  }
1366
+
1367
  /**
1368
  * Alert the user when 5 images have been re-optimized more than 10 times.
1369
  *
1557
  $ewwwdb->update(
1558
  $ewwwdb->ewwwio_images,
1559
  array(
1560
+ 'path' => ewww_image_optimizer_relativize_path( $new_filepath ),
1561
  ),
1562
  array(
1563
  'id' => $optimized_query['id'],
1842
  ewwwio_debug_message( "$nonce is fine, compared to $current_nonce" );
1843
  }
1844
  if ( ! empty( $attachment['path'] ) ) {
1845
+ $attachment['path'] = ewww_image_optimizer_absolutize_path( $attachment['path'] );
1846
  }
1847
  ewww_image_optimizer_aux_images_loop( $attachment, true );
1848
  if ( ! empty( $delay ) && ewww_image_optimizer_function_exists( 'sleep' ) ) {
2025
  $ewwwdb->update(
2026
  $ewwwdb->ewwwio_images,
2027
  array(
2028
+ 'path' => ewww_image_optimizer_relativize_path( $retina_path ),
2029
  'attachment_id' => $id,
2030
  'gallery' => 'media',
2031
  ),
2230
  return false;
2231
  }
2232
 
2233
+ /**
2234
+ * Filter the filename past any folders the user chose to ignore.
2235
+ *
2236
+ * @param bool $bypass True to skip optimization, defaults to false.
2237
+ * @param string $filename The file about to be optimized.
2238
+ * @return bool True if the file matches any folders to ignore.
2239
+ */
2240
+ function ewww_image_optimizer_ignore_file( $bypass, $filename ) {
2241
+ $ignore_folders = ewww_image_optimizer_get_option( 'ewww_image_optimizer_exclude_paths' );
2242
+ if ( ! ewww_image_optimizer_iterable( $ignore_folders ) ) {
2243
+ return $bypass;
2244
+ }
2245
+ foreach ( $ignore_folders as $ignore_folder ) {
2246
+ if ( strpos( $filename, $ignore_folder ) !== false ) {
2247
+ return true;
2248
+ }
2249
+ }
2250
+ return $bypass;
2251
+ }
2252
+
2253
  /**
2254
  * Sanitize the list of disabled resizes.
2255
  *
2420
  */
2421
  function ewww_image_optimizer_jpg_background( $background = null ) {
2422
  ewwwio_debug_message( '<b>' . __FUNCTION__ . '()</b>' );
2423
+ if ( is_null( $background ) ) {
2424
  // Retrieve the user-supplied value for jpg background color.
2425
  $background = ewww_image_optimizer_get_option( 'ewww_image_optimizer_jpg_background' );
2426
  }
2450
  */
2451
  function ewww_image_optimizer_jpg_quality( $quality = null ) {
2452
  ewwwio_debug_message( '<b>' . __FUNCTION__ . '()</b>' );
2453
+ if ( is_null( $quality ) ) {
2454
  // Retrieve the user-supplied value for jpg quality.
2455
  $quality = ewww_image_optimizer_get_option( 'ewww_image_optimizer_jpg_quality' );
2456
  }
2470
  }
2471
  }
2472
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2473
  /**
2474
  * Overrides the default JPG quality for WordPress image editing operations.
2475
  *
2636
  return $meta;
2637
  }
2638
  }
2639
+ $ewww_image = new EWWW_Image( $id, 'media', ewww_image_optimizer_absolutize_path( $db_image['path'] ) );
2640
  return $ewww_image->restore_with_meta( $meta );
2641
  }
2642
 
2661
  $images = $ewwwdb->get_results( "SELECT id,path,backup FROM $ewwwdb->ewwwio_images WHERE attachment_id = $id AND gallery = '$gallery'", ARRAY_A );
2662
  foreach ( $images as $image ) {
2663
  if ( ! empty( $image['path'] ) ) {
2664
+ $image['path'] = ewww_image_optimizer_absolutize_path( $image['path'] );
2665
  }
2666
  ewww_image_optimizer_cloud_restore_single_image( $image );
2667
  }
2721
  $image = $ewwwdb->get_row( "SELECT id,path,backup FROM $ewwwdb->ewwwio_images WHERE id = $image", ARRAY_A );
2722
  }
2723
  if ( ! empty( $image['path'] ) ) {
2724
+ $image['path'] = ewww_image_optimizer_absolutize_path( $image['path'] );
2725
  }
2726
  $api_key = ewww_image_optimizer_get_option( 'ewww_image_optimizer_cloud_key' );
2727
  $domain = parse_url( get_site_url(), PHP_URL_HOST );
2798
  if ( ewww_image_optimizer_iterable( $optimized_images ) ) {
2799
  foreach ( $optimized_images as $image ) {
2800
  if ( ! empty( $image['path'] ) ) {
2801
+ $image['path'] = ewww_image_optimizer_absolutize_path( $image['path'] );
2802
  }
2803
  if ( strpos( $image['path'], WP_CONTENT_DIR ) === false ) {
2804
  continue;
2810
  }
2811
  }
2812
  if ( ! empty( $image['converted'] ) ) {
2813
+ $image['converted'] = ewww_image_optimizer_absolutize_path( $image['converted'] );
2814
  }
2815
  if ( ! empty( $image['converted'] ) && is_file( $image['converted'] ) ) {
2816
  unlink( $image['converted'] );
2846
  // If the original file still exists and no posts contain links to the image.
2847
  if ( is_file( $file_path ) && empty( $rows ) ) {
2848
  unlink( $file_path );
2849
+ $ewwwdb->delete( $ewwwdb->ewwwio_images, array( 'path' => ewww_image_optimizer_relativize_path( $file_path ) ) );
2850
  }
2851
  }
2852
  // Remove the regular image from the ewwwio_images tables.
2853
  list( $file_path, $upload_path ) = ewww_image_optimizer_attachment_path( $meta, $id );
2854
+ $ewwwdb->delete( $ewwwdb->ewwwio_images, array( 'path' => ewww_image_optimizer_relativize_path( $file_path ) ) );
2855
  // Resized versions, so we can continue.
2856
  if ( isset( $meta['sizes'] ) && ewww_image_optimizer_iterable( $meta['sizes'] ) ) {
2857
  // One way or another, $file_path is now set, and we can get the base folder name.
2866
  if ( is_file( $webpfileold ) ) {
2867
  unlink( $webpfileold );
2868
  }
2869
+ $ewwwdb->delete( $ewwwdb->ewwwio_images, array( 'path' => ewww_image_optimizer_relativize_path( $base_dir . $data['file'] ) ) );
2870
  // If the original resize is set, and still exists.
2871
  if ( ! empty( $data['orig_file'] ) && is_file( $base_dir . $data['orig_file'] ) ) {
2872
  unset( $srows );
2878
  // If there are no posts containing links to the original, delete it.
2879
  if ( empty( $srows ) ) {
2880
  unlink( $base_dir . $data['orig_file'] );
2881
+ $ewwwdb->delete( $ewwwdb->ewwwio_images, array( 'path' => ewww_image_optimizer_relativize( $base_dir . $data['orig_file'] ) ) );
2882
  }
2883
  }
2884
  }
3846
  $results_msg = ewww_image_optimizer_image_results( $orig_size, $opt_size, $prev_string );
3847
 
3848
  $updates = array(
3849
+ 'path' => ewww_image_optimizer_relativize_path( $attachment ),
3850
  'converted' => $converted,
3851
  'level' => 0,
3852
  'image_size' => $opt_size,
4029
  $attachment = $attachment['path'];
4030
  }
4031
  if ( $attachment ) {
4032
+ $attachment = ewww_image_optimizer_absolutize_path( $attachment );
4033
  }
4034
  // Do the optimization for the current image.
4035
  $results = ewww_image_optimizer( $attachment );
4074
  global $ewww_debug;
4075
  $output['results'] .= '<div style="background-color:#ffff99;">' . $ewww_debug . '</div>';
4076
  }
4077
+ $next_file = ewww_image_optimizer_absolutize_path( $wpdb->get_var( "SELECT path FROM $wpdb->ewwwio_images WHERE pending=1 LIMIT 1" ) );
4078
  if ( ! empty( $next_file ) ) {
4079
  $loading_image = plugins_url( '/images/wpspin.gif', __FILE__ );
4080
  $output['next_file'] = '<p>' . esc_html__( 'Optimizing', 'ewww-image-optimizer' ) . ' <b>' . esc_html( $next_file ) . "</b>&nbsp;<img src='$loading_image' alt='loading'/></p>";
4378
  $ewwwdb->update(
4379
  $ewwwdb->ewwwio_images,
4380
  array(
4381
+ 'path' => ewww_image_optimizer_relativize_path( $local_path ),
4382
  ),
4383
  array(
4384
  'id' => $s3_image['id'],
4560
  return;
4561
  }
4562
  $ewww_image = new EWWW_Image( 0, '', $file );
4563
+ // Pass the filename, false for db search/replace, and true for filesize comparison.
4564
+ return $ewww_image->convert( $file, false, true );
4565
  }
4566
 
4567
  /**
4776
  $tmp_exists = $ewwwdb->update(
4777
  $ewwwdb->ewwwio_images,
4778
  array(
4779
+ 'path' => ewww_image_optimizer_relativize_path( $file ),
4780
  'orig_size' => $orig_size,
4781
  ),
4782
  array(
4783
+ 'path' => ewww_image_optimizer_relativize_path( $new_file ),
4784
  )
4785
  );
4786
  // If the tmp file didn't get optimized (and it shouldn't), then just insert a dummy record to be updated shortly.
4788
  $ewwwdb->insert(
4789
  $ewwwdb->ewwwio_images,
4790
  array(
4791
+ 'path' => ewww_image_optimizer_relativize_path( $file ),
4792
  'orig_size' => $orig_size,
4793
  )
4794
  );
4858
  } else {
4859
  $ewwwdb = $wpdb;
4860
  }
4861
+ $maybe_return_image = false;
4862
+ $maybe_relative_path = ewww_image_optimizer_relativize_path( $attachment );
4863
+ $query = $ewwwdb->prepare( "SELECT * FROM $ewwwdb->ewwwio_images WHERE path = %s", $maybe_relative_path );
4864
+ $optimized_query = $ewwwdb->get_results( $query, ARRAY_A );
4865
+ if ( empty( $optimized_query ) && $attachment !== $maybe_relative_path ) {
4866
+ $query = $ewwwdb->prepare( "SELECT * FROM $ewwwdb->ewwwio_images WHERE path = %s", $attachment );
4867
+ $optimized_query = $ewwwdb->get_results( $query, ARRAY_A );
4868
+ }
4869
  if ( ewww_image_optimizer_iterable( $optimized_query ) ) {
4870
  foreach ( $optimized_query as $image ) {
4871
+ $image['path'] = ewww_image_optimizer_absolutize_path( $image['path'] );
4872
  if ( $image['path'] != $attachment ) {
4873
  ewwwio_debug_message( "{$image['path']} does not match $attachment, continuing our search" );
4874
  } elseif ( ! $maybe_return_image ) {
5201
  $ewwwdb->update(
5202
  $ewwwdb->ewwwio_images,
5203
  array(
5204
+ 'path' => ewww_image_optimizer_relativize_path( $file_path ),
5205
  'attachment_id' => $id,
5206
  'resize' => 'full',
5207
  'gallery' => 'media',
5360
  $ewwwdb->update(
5361
  $ewwwdb->ewwwio_images,
5362
  array(
5363
+ 'path' => ewww_image_optimizer_relativize_path( $ims_path ),
5364
  ),
5365
  array(
5366
  'id' => $already_optimized['id'],
5881
  * @param string $file The filename to mangle.
5882
  * @return string The filename with parent folders replaced by a constant name.
5883
  */
5884
+ function ewww_image_optimizer_relativize_path( $file ) {
5885
  if ( ! defined( 'EWWW_IMAGE_OPTIMIZER_RELATIVE' ) || ! EWWW_IMAGE_OPTIMIZER_RELATIVE ) {
5886
  return $file;
5887
  }
5906
  *
5907
  * Replaces the literal strings 'ABSPATH', 'WP_CONTENT_DIR', or
5908
  * 'EWWW_IMAGE_OPTIMIZER_RELATIVE_FOLDER' with the actual value of the constant contained within
5909
+ * the file path.
5910
  *
5911
  * @param string $file The filename to parse.
5912
  * @return string The full filename with parent folders reinserted.
5913
  */
5914
+ function ewww_image_optimizer_absolutize_path( $file ) {
5915
  if ( ! defined( 'EWWW_IMAGE_OPTIMIZER_RELATIVE' ) ) {
5916
  return $file;
5917
  }
8379
  if ( ! empty( $ewww_debug ) && ewww_image_optimizer_get_option( 'ewww_image_optimizer_debug' ) ) {
8380
  $memory_limit = ewwwio_memory_limit();
8381
  clearstatcache();
8382
+ $timestamp = date( 'Y-m-d H:i:s' ) . "\n";
8383
  if ( ! file_exists( EWWW_IMAGE_OPTIMIZER_PLUGIN_PATH . 'debug.log' ) ) {
8384
  touch( EWWW_IMAGE_OPTIMIZER_PLUGIN_PATH . 'debug.log' );
8385
  } else {
ewww-image-optimizer.php CHANGED
@@ -14,7 +14,7 @@ Plugin URI: https://wordpress.org/plugins/ewww-image-optimizer/
14
  Description: Reduce file sizes for images within WordPress including NextGEN Gallery and GRAND FlAGallery. Uses jpegtran, optipng/pngout, and gifsicle.
15
  Author: Exactly WWW
16
  Text Domain: ewww-image-optimizer
17
- Version: 4.5.1
18
  Author URI: https://ewww.io/
19
  License: GPLv3
20
  */
14
  Description: Reduce file sizes for images within WordPress including NextGEN Gallery and GRAND FlAGallery. Uses jpegtran, optipng/pngout, and gifsicle.
15
  Author: Exactly WWW
16
  Text Domain: ewww-image-optimizer
17
+ Version: 4.5.2
18
  Author URI: https://ewww.io/
19
  License: GPLv3
20
  */
includes/eio.js CHANGED
@@ -355,6 +355,7 @@ jQuery(document).ready(function($) {
355
  var ewww_total_pages = Math.ceil(ewww_vars.image_count / 50);
356
  $('.ewww-aux-table').show();
357
  $('#ewww-show-table').hide();
 
358
  if (ewww_vars.image_count >= 50) {
359
  $('.tablenav').show();
360
  $('#next-images').show();
@@ -487,6 +488,7 @@ jQuery(document).ready(function($) {
487
  $('#ewww-bulk-stop').show();
488
  $('.ewww-bulk-form').hide();
489
  $('.ewww-bulk-info').hide();
 
490
  $('h2').hide();
491
  $.post(ajaxurl, ewww_init_data, function(response) {
492
  var is_json = true;
355
  var ewww_total_pages = Math.ceil(ewww_vars.image_count / 50);
356
  $('.ewww-aux-table').show();
357
  $('#ewww-show-table').hide();
358
+ $('#ewww-table-info').hide();
359
  if (ewww_vars.image_count >= 50) {
360
  $('.tablenav').show();
361
  $('#next-images').show();
488
  $('#ewww-bulk-stop').show();
489
  $('.ewww-bulk-form').hide();
490
  $('.ewww-bulk-info').hide();
491
+ $('#ewww-bulk-forms').hide();
492
  $('h2').hide();
493
  $.post(ajaxurl, ewww_init_data, function(response) {
494
  var is_json = true;
readme.txt CHANGED
@@ -5,7 +5,7 @@ Tags: image, compress, resize, optimize, optimization, lossless, lossy, seo, web
5
  Requires at least: 4.9
6
  Tested up to: 5.0
7
  Requires PHP: 5.6
8
- Stable tag: 4.5.1
9
  License: GPLv3
10
 
11
  Speed up your website and improve your visitors' experience by automatically compressing and resizing images and PDFs. Boost SEO and improve sales.
@@ -174,6 +174,12 @@ http://developer.yahoo.com/performance/rules.html#opt_images
174
  * Feature requests can be viewed and submitted at https://github.com/nosilver4u/ewww-image-optimizer/labels/enhancement
175
  * If you would like to help translate this plugin in your language, get started here: https://translate.wordpress.org/projects/wp-plugins/ewww-image-optimizer/
176
 
 
 
 
 
 
 
177
  = 4.5.1 =
178
  * changed: optimization results are tracked by relative urls instead of absolute ones for better portability, migration tool coming soon
179
  * changed: ExactDN defaults to crop when explicit dimensions are given to image_downsize(), revert to scaling with EXACTDN_IMAGE_DOWNSIZE_SCALE
5
  Requires at least: 4.9
6
  Tested up to: 5.0
7
  Requires PHP: 5.6
8
+ Stable tag: 4.5.2
9
  License: GPLv3
10
 
11
  Speed up your website and improve your visitors' experience by automatically compressing and resizing images and PDFs. Boost SEO and improve sales.
174
  * Feature requests can be viewed and submitted at https://github.com/nosilver4u/ewww-image-optimizer/labels/enhancement
175
  * If you would like to help translate this plugin in your language, get started here: https://translate.wordpress.org/projects/wp-plugins/ewww-image-optimizer/
176
 
177
+ = 4.5.2 =
178
+ * added: automatic migration to move image paths from absolute to relative
179
+ * changed: default quality for PNG to JPG did not match WordPress default
180
+ * fixed: legacy absolute paths not matched during bulk scanner when relative matching is enabled
181
+ * fixed: PNG to JPG auto-convert produces larger JPG images in some cases
182
+
183
  = 4.5.1 =
184
  * changed: optimization results are tracked by relative urls instead of absolute ones for better portability, migration tool coming soon
185
  * changed: ExactDN defaults to crop when explicit dimensions are given to image_downsize(), revert to scaling with EXACTDN_IMAGE_DOWNSIZE_SCALE
tests/test-optimize.php CHANGED
@@ -441,7 +441,7 @@ class EWWWIO_Optimize_Tests extends WP_UnitTestCase {
441
  $results = $this->optimize_pdf();
442
  update_option( 'ewww_image_optimizer_cloud_key', '' );
443
  update_site_option( 'ewww_image_optimizer_cloud_key', '' );
444
- $this->assertLessThan( 128400, filesize( $results[0] ) );
445
  unlink( $results[0] );
446
  }
447
 
441
  $results = $this->optimize_pdf();
442
  update_option( 'ewww_image_optimizer_cloud_key', '' );
443
  update_site_option( 'ewww_image_optimizer_cloud_key', '' );
444
+ $this->assertLessThan( 129000, filesize( $results[0] ) );
445
  unlink( $results[0] );
446
  }
447
 
tests/test-utility.php CHANGED
@@ -99,9 +99,9 @@ class EWWWIO_Utility_Tests extends WP_UnitTestCase {
99
  define( 'EWWW_IMAGE_OPTIMIZER_RELATIVE', true );
100
  }
101
  $test_image = trailingslashit( ABSPATH ) . 'images/test.png';
102
- $relative_test_image_path = ewww_image_optimizer_relative_path_remove( $test_image );
103
  $this->assertEquals( 'ABSPATHimages/test.png', $relative_test_image_path );
104
- $replaced_test_image = ewww_image_optimizer_relative_path_replace( $relative_test_image_path );
105
  $this->assertEquals( $test_image, $replaced_test_image );
106
  }
107
  }
99
  define( 'EWWW_IMAGE_OPTIMIZER_RELATIVE', true );
100
  }
101
  $test_image = trailingslashit( ABSPATH ) . 'images/test.png';
102
+ $relative_test_image_path = ewww_image_optimizer_relativize_path( $test_image );
103
  $this->assertEquals( 'ABSPATHimages/test.png', $relative_test_image_path );
104
+ $replaced_test_image = ewww_image_optimizer_absolutize_path( $relative_test_image_path );
105
  $this->assertEquals( $test_image, $replaced_test_image );
106
  }
107
  }
unique.php CHANGED
@@ -2098,16 +2098,8 @@ function ewww_image_optimizer( $file, $gallery_type = 4, $converted = false, $ne
2098
  // Set the background flag for 'convert'.
2099
  $background = '-background ' . '"' . "#$background" . '"';
2100
  }
2101
- $cquality = '';
2102
- $gquality = '92';
2103
- // If the user manually set the JPG quality.
2104
- $quality = ewww_image_optimizer_jpg_quality();
2105
- if ( $quality ) {
2106
- // Set the quality for GD.
2107
- $gquality = $quality;
2108
- // Set the quality flag for 'convert'.
2109
- $cquality = "-quality $quality";
2110
- }
2111
  // If this is a resize version.
2112
  if ( $converted ) {
2113
  // Just replace the file extension with a .jpg.
2098
  // Set the background flag for 'convert'.
2099
  $background = '-background ' . '"' . "#$background" . '"';
2100
  }
2101
+ $gquality = ewww_image_optimizer_jpg_quality();
2102
+ $gquality = $gquality ? $gquality : '82';
 
 
 
 
 
 
 
 
2103
  // If this is a resize version.
2104
  if ( $converted ) {
2105
  // Just replace the file extension with a .jpg.