Resize Image After Upload - Version 1.8.0

Version Description

Release date: 18th June 2017

  • [Update] Add convert PNG to JPG option
Download this release

Release Info

Developer jepsonrae
Plugin Icon 128x128 Resize Image After Upload
Version 1.8.0
Comparing to
See all releases

Code changes from version 1.7.2 to 1.8.0

Files changed (3) hide show
  1. img/sp.png +0 -0
  2. readme.txt +28 -12
  3. resize-image-after-upload.php +130 -26
img/sp.png ADDED
Binary file
readme.txt CHANGED
@@ -1,26 +1,25 @@
1
  === Resize Image After Upload ===
2
  Contributors: ShortPixel
3
- Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=3W4M254AA3KZG
4
- Tags: image, processing, plugin, resize, upload, resizing, optimization, optimize, optimise, optimisation, downsize, imsanity, bulk resize
5
  Requires at least: 3.5
6
- Tested up to: 4.3.1
7
- Stable tag: 1.7.2
8
 
9
- Behind-the-scenes plugin to automatically resize images when uploaded, restricting size to within specified maximum h/w. Uses standard WP functions.
10
 
11
  == Description ==
12
 
13
- This plugin automatically resizes images (JPEG, GIF, and PNG) when they are uploaded to within a given maximum width and/or height to reduce server space usage. This may be necessary due to the fact that images from digital cameras and smartphones can now be over 10MB each due to higher megapixel counts.
14
 
15
- In addition, the plugin can force re-compression of uploaded JPEG images, regardless of whether they are resized or not.
 
16
 
17
- **NOTE 1** - This plugin will *not* resize images that have already been uploaded.
18
 
19
- **NOTE 2** - The resizing/recompression process will discard the original uploaded file including EXIF data.
20
 
21
- This plugin is not intended to replace the WordPress *add_image_size()* function, but rather complement it. Use this plugin to ensure that no excessively large images are stored on your server, then use *add_image_size()* to create versions of the images suitable for positioning in your website theme.
22
-
23
- This plugin uses standard WordPress image resizing functions and will require a high amount of memory (RAM) to be allocated to PHP in your php.ini file (e.g 512MB).
24
 
25
  == Installation ==
26
 
@@ -29,12 +28,29 @@ This plugin uses standard WordPress image resizing functions and will require a
29
  3. Edit the max-width/max-height settings under 'Settings > Resize Image Upload'.
30
  4. Once active, just upload images as normal and it will just work!
31
 
 
 
 
 
 
 
 
 
 
 
 
32
  == Screenshots ==
33
 
34
  1. Full preview of the settings screen.
35
 
36
  == Changelog ==
37
 
 
 
 
 
 
 
38
  = 1.7.2 =
39
 
40
  Release date: 18th September 2015
1
  === Resize Image After Upload ===
2
  Contributors: ShortPixel
3
+ Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=TKZHGYG2UCFUQ
4
+ Tags: image, resize, rescale, bulk resize, bulk rescale, downsize,
5
  Requires at least: 3.5
6
+ Tested up to: 4.8
7
+ Stable tag: 1.8.0
8
 
9
+ Automatically resize your images after upload using this plugin. Specify height&width, the plugin will do the rest quickly and transparently.
10
 
11
  == Description ==
12
 
13
+ **A free, fast, easy to use, stable and frequently updated plugin to resize your images after upload. Supported by the friendly team that created <a href="https://wordpress.org/plugins/shortpixel-image-optimiser/" target="_blank">ShortPixel</a> :)**
14
 
15
+ This plugin automatically resizes images (JPEG, GIF, and PNG) when they are uploaded to within a given maximum width and/or height to reduce server space usage, speed up your website, save you time and boost your site's SEO.
16
+ Imagine that nowadays images can be over 4-5MB and using this plugin you can reduce them to 100-200KB with no extra effort on your side!
17
 
18
+ In addition, the plugin can force re-compression of uploaded JPEG images and convert PNGs to JPEG (if they don't have a transparency layer), regardless of whether they are resized or not.
19
 
20
+ Is that simple, just give it a try, it is safe and free! :-)
21
 
22
+ **Keywords:** image, picture, processing, plugin, resize, upload, resizing, optimization, optimize, optimise, optimisation, downsize, imsanity, bulk resize, compress, shrink, picture, performance, fast, images, image files, image quality, image optimizer, jpg optimisation, jpg optimization, jpg resizing, png optimisation, png optimization, png resizing, image cruncher, compress png, compress jpg, compress jpeg, faster, loading times, bandwidth, pics, remove exif, speed up site, speed up website
 
 
23
 
24
  == Installation ==
25
 
28
  3. Edit the max-width/max-height settings under 'Settings > Resize Image Upload'.
29
  4. Once active, just upload images as normal and it will just work!
30
 
31
+ == Frequently Asked Questions ==
32
+
33
+ = Is this plugin compressing the images? =
34
+ Yes, this plugin compresses the original images, you can select the JPEG quality for example. For a professional image optimization solution though we recommend you <a rel="friend" href="https://wordpress.org/plugins/shortpixel-image-optimiser/" target="_blank">this</a> image optimization plugin.
35
+
36
+ = Is this plugin resizing also older images? =
37
+ This plugin will *not* resize images that have already been uploaded. For this you can use <a rel="friend" href="https://wordpress.org/plugins/shortpixel-image-optimiser/" target="_blank">ShortPixel</a>, it can not only resize your images but it can compressthem as well!
38
+
39
+ = Is the original image and/or its EXIF data kept? =
40
+ The resizing/recompression process will discard the original uploaded file including EXIF data.
41
+
42
  == Screenshots ==
43
 
44
  1. Full preview of the settings screen.
45
 
46
  == Changelog ==
47
 
48
+ = 1.8.0 =
49
+
50
+ Release date: 18th June 2017
51
+
52
+ * [Update] Add convert PNG to JPG option
53
+
54
  = 1.7.2 =
55
 
56
  Release date: 18th September 2015
resize-image-after-upload.php CHANGED
@@ -2,9 +2,9 @@
2
  /*
3
  Plugin Name: Resize Image After Upload
4
  Plugin URI: https://wordpress.org/plugins/resize-image-after-upload/
5
- Description: Simple plugin to automatically resize uploaded images to within specified maximum width and height. Also has option to force recompression of JPEGs. Configuration options found under <a href="options-general.php?page=resize-after-upload">Settings > Resize Image Upload</a>
6
  Author: ShortPixel
7
- Version: 1.7.2
8
  Author URI: https://shortpixel.com
9
 
10
  Copyright (C) 2017 ShortPixel
@@ -24,7 +24,7 @@ along with this program; if not, write to the Free Software
24
  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
25
  */
26
 
27
- $PLUGIN_VERSION = '1.7.2';
28
  $DEBUG_LOGGER = false;
29
 
30
 
@@ -50,15 +50,58 @@ add_action('admin_menu', 'jr_uploadresize_options_page');
50
  // Hook the function to the upload handler
51
  add_action('wp_handle_upload', 'jr_uploadresize_resize');
52
 
 
53
 
 
 
54
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
55
 
56
  /**
57
  * Add the options page
58
  */
59
  function jr_uploadresize_options_page(){
 
60
  if(function_exists('add_options_page')){
61
- add_options_page(
62
  'Resize Image After Upload',
63
  'Resize Image Upload',
64
  'manage_options',
@@ -209,14 +252,10 @@ function jr_uploadresize_options(){
209
 
210
  <h4 style="font-size: 15px;font-weight: bold;margin: 2em 0 0;">Like the plugin?</h4>
211
 
212
- <p>This plugin was written and is maintained for free (as in free beer) by me, <a href="http://philr.ae" target="_blank">Phil Rae</a>. If you find it useful please consider donating some small change or bitcoins to my beer fund because beer is very seldom free. Thanks!</p>
213
 
214
  <p style="padding-bottom:2em;" class="resizeimage-button-wrapper">
215
-
216
- <a class="resizeimage-button" href="https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=3W4M254AA3KZG" target="_blank">Donate cash</a>
217
-
218
- <a class="resizeimage-button coinbase-button" data-code="9584265cb76df0b1e99979163de143f5" data-button-style="custom_small" target="_blank" href="https://coinbase.com/checkouts/9584265cb76df0b1e99979163de143f5">Donate bitcoins</a>
219
-
220
  </p>
221
  </div>
222
 
@@ -287,16 +326,42 @@ function jr_uploadresize_options(){
287
 
288
  </table>
289
 
290
- <?php /* DEFINED HERE FOR FUTURE RELEASE - does not do anything if uncommented
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
291
  <hr style="margin-top:20px; margin-bottom:20px;">
292
 
293
  <h3>Image conversion options</h3>
294
- <p style="max-width:700px">Photos saved as PNG and GIF images can be extremely large in file size due to their compression methods not being suited for photos. Enable these options below to automatically convert GIF and/or PNG images to JPEG.</p>
295
 
296
- <p>When enabled, conversion will happen to all uploaded GIF/PNG images, not just ones that require resizing.</p>
297
 
298
  <table class="form-table">
299
 
 
 
 
 
 
 
 
 
 
 
 
300
  <tr>
301
  <th scope="row">Convert GIF to JPEG</th>
302
  <td>
@@ -307,18 +372,9 @@ function jr_uploadresize_options(){
307
  </td>
308
  </tr>
309
 
310
- <tr>
311
- <th scope="row">Convert PNG to JPEG</th>
312
- <td>
313
- <select id="convert-png" name="convertpng">
314
- <option value="no" <?php if($convert_png_to_jpg == 'no') : ?>selected<?php endif; ?>>NO - just resize uploaded png images as normal</option>
315
- <option value="yes" <?php if($convert_png_to_jpg == 'yes') : ?>selected<?php endif; ?>>YES - convert all uploaded png images to jpeg</option>
316
- </select>
317
- </td>
318
- </tr>
319
 
320
  </table>
321
- */ ?>
322
 
323
  <hr style="margin-top:30px;">
324
 
@@ -348,14 +404,13 @@ function jr_uploadresize_resize($image_data){
348
 
349
 
350
  $resizing_enabled = get_option('jr_resizeupload_resize_yesno');
351
- $resizing_enabled = ($resizing_enabled=='yes') ? true : false;
352
 
353
  $force_jpeg_recompression = get_option('jr_resizeupload_recompress_yesno');
354
- $force_jpeg_recompression = ($force_jpeg_recompression=='yes') ? true : false;
355
 
356
  $compression_level = get_option('jr_resizeupload_quality');
357
 
358
-
359
  $max_width = get_option('jr_resizeupload_width')==0 ? false : get_option('jr_resizeupload_width');
360
 
361
  $max_height = get_option('jr_resizeupload_height')==0 ? false : get_option('jr_resizeupload_height');
@@ -371,6 +426,9 @@ function jr_uploadresize_resize($image_data){
371
  $convert_bmp_to_jpg = ($convert_bmp_to_jpg=='yes') ? true : false;
372
 
373
 
 
 
 
374
 
375
  //---------- In with the old v1.6.2, new v1.7 (WP_Image_Editor) ------------
376
 
@@ -461,6 +519,52 @@ function jr_uploadresize_resize($image_data){
461
  return $image_data;
462
  } // function jr_uploadresize_resize($image_data){
463
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
464
 
465
  /**
466
  * Simple debug logging function. Will only output to the log file
2
  /*
3
  Plugin Name: Resize Image After Upload
4
  Plugin URI: https://wordpress.org/plugins/resize-image-after-upload/
5
+ Description: Automatically resize uploaded images to within specified maximum width and height. Also has option to force recompression of JPEGs. Configuration options found under <a href="options-general.php?page=resize-after-upload">Settings > Resize Image Upload</a>
6
  Author: ShortPixel
7
+ Version: 1.8.0
8
  Author URI: https://shortpixel.com
9
 
10
  Copyright (C) 2017 ShortPixel
24
  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
25
  */
26
 
27
+ $PLUGIN_VERSION = '1.8.0';
28
  $DEBUG_LOGGER = false;
29
 
30
 
50
  // Hook the function to the upload handler
51
  add_action('wp_handle_upload', 'jr_uploadresize_resize');
52
 
53
+ add_filter( 'plugin_action_links_' . plugin_basename(__FILE__), 'jr_generate_plugin_links');//for plugin settings page
54
 
55
+ add_action('admin_notices', 'jr_display_notices');
56
+ add_action('wp_ajax_jr_dismiss_notices', 'jr_dismiss_notices');
57
 
58
+ /**
59
+ * Add ths link to Settings in Plugins Page
60
+ */
61
+ function jr_generate_plugin_links($links) {
62
+ $settings_link = '<a href="options-general.php?page=resize-after-upload">Settings</a>';
63
+ array_unshift( $links, $settings_link );
64
+ return $links;
65
+ }
66
+
67
+ function jr_display_notices() {
68
+ if(get_option( 'jr_resizeupload_news') !== 1 ) {
69
+ global $jr_settings_page;
70
+ $screen = get_current_screen();
71
+ if ( $screen->id != $jr_settings_page ) { ?>
72
+ <div class='notice notice-warning' id='jr-resizeupload-news' style="padding-top: 7px">
73
+ <div style="float:right;"><a href="javascript:jrResizeuploadDismissNews()" class="button" style="margin-top:10px;">Dismiss</a></div>
74
+ <strong>Resize Image After Upload</strong>
75
+ <p>Check out the <a href="options-general.php?page=resize-after-upload">Plugin settings</a> for new features that can make your site load faster.</p>
76
+ </div>
77
+ <script>
78
+ function jrResizeuploadDismissNews() {
79
+ jQuery("#jr-resizeupload-news").hide();
80
+ var data = { action : 'jr_dismiss_notices'};
81
+ jQuery.get('<?php echo admin_url('admin-ajax.php'); ?>', data, function(response) {
82
+ data = JSON.parse(response);
83
+ if(data["Status"] == 0) {
84
+ console.log("dismissed");
85
+ }
86
+ });
87
+ }
88
+ </script>
89
+ <?php }
90
+ }
91
+ }
92
+
93
+ function jr_dismiss_notices() {
94
+ update_option( 'jr_resizeupload_news', 1);
95
+ return json_encode(array("Status" => 0));
96
+ }
97
 
98
  /**
99
  * Add the options page
100
  */
101
  function jr_uploadresize_options_page(){
102
+ global $jr_settings_page;
103
  if(function_exists('add_options_page')){
104
+ $jr_settings_page = add_options_page(
105
  'Resize Image After Upload',
106
  'Resize Image Upload',
107
  'manage_options',
252
 
253
  <h4 style="font-size: 15px;font-weight: bold;margin: 2em 0 0;">Like the plugin?</h4>
254
 
255
+ <p>This plugin was written for free (as in free beer) by me, <a href="http://philr.ae" target="_blank">Phil Rae</a>. If you find it useful please consider donating some small change to my beer fund because beer is very seldom free. Thanks!</p>
256
 
257
  <p style="padding-bottom:2em;" class="resizeimage-button-wrapper">
258
+ <a class="resizeimage-button" href="https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=TKZHGYG2UCFUQ" target="_blank">Donate cash</a>
 
 
 
 
259
  </p>
260
  </div>
261
 
326
 
327
  </table>
328
 
329
+ <p class="description"><strong>
330
+ Note that any changes you make will only affect new images uploaded to your site. A specialized plugin can optimize all your present images and will also optimize new ones as they are added.
331
+ </strong></p>
332
+ <p class="description" style="font-size:1.1em;margin: 15px 0;"><strong>
333
+ <a href="https://shortpixel.com/riau/af/WVCLIKV28044?autoreferrer=1" target="_blank">
334
+ Test your website with ShortPixel for free to see how much you could gain by optimizing your images
335
+ </a>
336
+ </strong></p>
337
+ <a href="https://shortpixel.com/riau/af/WVCLIKV28044?autoreferrer=1" target="_blank"><img src="<?php echo plugins_url(); ?>/resize-image-after-upload/img/sp.png" style="float:left;margin-right:20px;"/></a>
338
+ <p class="description">
339
+ ShortPixel is an easy to use, comprehensive, stable and frequently updated image optimization plugin supported by the friendly team that created it. Using a powerful set of specially tuned algorithms, it squeezes the most of each image striking the best balance between image size and quality. Current images can be all optimized with a single click. Newly added images are automatically resized/rescaled and optimized on the fly, in the background.
340
+ </p>
341
+ <p class="description-link">
342
+ <a href="https://shortpixel.com/riau/af/WVCLIKV28044?autoreferrer=1" target="_blank">&gt;&gt; <?php _e( 'More info', 'sb-pack' ); ?></a>
343
+ </p>
344
+
345
  <hr style="margin-top:20px; margin-bottom:20px;">
346
 
347
  <h3>Image conversion options</h3>
348
+ <p style="max-width:700px">Photos saved as PNG <?php //and GIF ?> images can be extremely large in file size due to their compression methods not being suited for photos. Enable these options below to automatically convert <?php //GIF and/or ?>PNG images to JPEG <strong>only if they don't have transparency</strong></strong>.</p>
349
 
350
+ <p>When enabled, conversion will happen to all suitable uploaded PNG images, not just ones that require resizing.</p>
351
 
352
  <table class="form-table">
353
 
354
+ <tr>
355
+ <th scope="row">Convert PNG to JPEG</th>
356
+ <td>
357
+ <select id="convert-png" name="convertpng">
358
+ <option value="no" <?php if($convert_png_to_jpg == 'no') : ?>selected<?php endif; ?>>NO - just resize uploaded png images as normal</option>
359
+ <option value="yes" <?php if($convert_png_to_jpg == 'yes') : ?>selected<?php endif; ?>>YES - convert all uploaded png images not having a transparency layer to jpeg</option>
360
+ </select>
361
+ </td>
362
+ </tr>
363
+
364
+ <?php /* DEFINED HERE FOR FUTURE RELEASE - does not do anything if uncommented
365
  <tr>
366
  <th scope="row">Convert GIF to JPEG</th>
367
  <td>
372
  </td>
373
  </tr>
374
 
375
+ */ ?>
 
 
 
 
 
 
 
 
376
 
377
  </table>
 
378
 
379
  <hr style="margin-top:30px;">
380
 
404
 
405
 
406
  $resizing_enabled = get_option('jr_resizeupload_resize_yesno');
407
+ $resizing_enabled = ($resizing_enabled=='yes') ? true : false;
408
 
409
  $force_jpeg_recompression = get_option('jr_resizeupload_recompress_yesno');
410
+ $force_jpeg_recompression = ($force_jpeg_recompression=='yes') ? true : false;
411
 
412
  $compression_level = get_option('jr_resizeupload_quality');
413
 
 
414
  $max_width = get_option('jr_resizeupload_width')==0 ? false : get_option('jr_resizeupload_width');
415
 
416
  $max_height = get_option('jr_resizeupload_height')==0 ? false : get_option('jr_resizeupload_height');
426
  $convert_bmp_to_jpg = ($convert_bmp_to_jpg=='yes') ? true : false;
427
 
428
 
429
+ if($convert_png_to_jpg && $image_data['type'] == 'image/png' ) {
430
+ $image_data = jr_uploadresize_convert_image( $image_data, $compression_level );
431
+ }
432
 
433
  //---------- In with the old v1.6.2, new v1.7 (WP_Image_Editor) ------------
434
 
519
  return $image_data;
520
  } // function jr_uploadresize_resize($image_data){
521
 
522
+ function jr_uploadresize_convert_image( $params, $compression_level ){
523
+ $transparent = 0;
524
+ $image = $params['file'];
525
+
526
+ $contents = file_get_contents( $image );
527
+ if ( ord ( file_get_contents( $image, false, null, 25, 1 ) ) & 4 ) $transparent = 1;
528
+ if ( stripos( $contents, 'PLTE' ) !== false && stripos( $contents, 'tRNS' ) !== false ) $transparent = 1;
529
+
530
+ $transparent_pixel = $img = $bg = false;
531
+ if($transparent) {
532
+ $img = imagecreatefrompng($params['file']);
533
+ $w = imagesx($img); // Get the width of the image
534
+ $h = imagesy($img); // Get the height of the image
535
+ //run through pixels until transparent pixel is found:
536
+ for($i = 0; $i<$w; $i++) {
537
+ for($j = 0; $j < $h; $j++) {
538
+ $rgba = imagecolorat($img, $i, $j);
539
+ if(($rgba & 0x7F000000) >> 24) {
540
+ $transparent_pixel = true;
541
+ break;
542
+ }
543
+ }
544
+ }
545
+ }
546
+
547
+ if( !$transparent || !$transparent_pixel) {
548
+ if(!$img) $img = imagecreatefrompng($params['file']);
549
+ $bg = imagecreatetruecolor(imagesx($img), imagesy($img));
550
+ imagefill($bg, 0, 0, imagecolorallocate($bg, 255, 255, 255));
551
+ imagealphablending($bg, 1);
552
+ imagecopy($bg, $img, 0, 0, 0, 0, imagesx($img), imagesy($img));
553
+ $newPath = preg_replace("/\.png$/", ".jpg", $params['file']);
554
+ $newUrl = preg_replace("/\.png$/", ".jpg", $params['url']);
555
+ for($i = 1; file_exists($newPath); $i++) {
556
+ $newPath = preg_replace("/\.png$/", "-".$i.".jpg", $params['file']);
557
+ }
558
+ if ( imagejpeg( $bg, $newPath, $compression_level ) ){
559
+ unlink($params['file']);
560
+ $params['file'] = $newPath;
561
+ $params['url'] = $newUrl;
562
+ $params['type'] = 'image/jpeg';
563
+ }
564
+ }
565
+
566
+ return $params;
567
+ }
568
 
569
  /**
570
  * Simple debug logging function. Will only output to the log file