Resize Image After Upload - Version 1.5.0

Version Description

  • [Added] Ability to force re-compression even if resize is not required.
  • [Fix] Compression quality value was not adhered to.
Download this release

Release Info

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

Code changes from version 1.4.2 to 1.5.0

Files changed (3) hide show
  1. class.resize.php +17 -11
  2. readme.txt +12 -8
  3. resize-image-after-upload.php +85 -22
class.resize.php CHANGED
@@ -82,7 +82,7 @@ class RVJ_ImageResize {
82
  */
83
 
84
  function __constructor($strPath, $strSavePath, $strType = "W", $value = "150", $boolProtect = true, $numQuality = 95){
85
- $this->RVJ_ImageResize($strPath, $strSavePath, $strType, $value);
86
  }
87
 
88
  /*
@@ -270,14 +270,19 @@ class RVJ_ImageResize {
270
  function _resize($numWidth, $numHeight, $numQuality=95){
271
  //check for image protection
272
  if($this->_imageProtect($numWidth, $numHeight)){
 
 
273
  if($this->arrOriginalDetails['mime']=="image/gif"){
274
- //GIF image
275
  $this->resResizedImage = imagecreate($numWidth, $numHeight);
276
- }else if($this->arrOriginalDetails['mime']=="image/jpeg"){
277
- //JPG image
 
 
278
  $this->resResizedImage = imagecreatetruecolor($numWidth, $numHeight);
279
- }else if($this->arrOriginalDetails['mime']=="image/png"){
280
- //PNG image
 
 
281
  $this->resResizedImage = imagecreatetruecolor($numWidth, $numHeight);
282
  imagecolortransparent($this->resResizedImage, imagecolorallocate($this->resResizedImage, 0, 0, 0));
283
  imagealphablending($this->resResizedImage, false);
@@ -291,6 +296,7 @@ class RVJ_ImageResize {
291
  } else {
292
  imagecopyresized($this->resResizedImage, $this->resOriginalImage, 0, 0, 0, 0, $numWidth, $numHeight, $this->arrOriginalDetails[0], $this->arrOriginalDetails[1]);
293
  }
 
294
  //saves the image
295
  $this->saveImage($numQuality);
296
  }
@@ -307,7 +313,7 @@ class RVJ_ImageResize {
307
  */
308
 
309
  function _imageProtect($numWidth, $numHeight){
310
- if($this->boolProtect AND ($numWidth > $this->arrOriginalDetails[0] OR $numHeight > $this->arrOriginalDetails[1])){
311
  return 0;
312
  }
313
  return 1;
@@ -338,7 +344,7 @@ class RVJ_ImageResize {
338
 
339
  function resizeToHeight($numHeight){
340
  $numWidth=(int)(($numHeight*$this->arrOriginalDetails[0])/$this->arrOriginalDetails[1]);
341
- $this->_resize($numWidth, $numHeight);
342
  }
343
 
344
  /*
@@ -353,7 +359,7 @@ class RVJ_ImageResize {
353
  function resizeToPercent($numPercent){
354
  $numWidth = (int)(($this->arrOriginalDetails[0]/100)*$numPercent);
355
  $numHeight = (int)(($this->arrOriginalDetails[1]/100)*$numPercent);
356
- $this->_resize($numWidth, $numHeight);
357
  }
358
 
359
  /*
@@ -367,9 +373,9 @@ class RVJ_ImageResize {
367
 
368
  function resizeToCustom($size){
369
  if(!is_array($size)){
370
- $this->_resize((int)$size, (int)$size);
371
  }else{
372
- $this->_resize((int)$size[0], (int)$size[1]);
373
  }
374
  }
375
  }
82
  */
83
 
84
  function __constructor($strPath, $strSavePath, $strType = "W", $value = "150", $boolProtect = true, $numQuality = 95){
85
+ $this->RVJ_ImageResize($strPath, $strSavePath, $strType, $value, $boolProtect, $numQuality);
86
  }
87
 
88
  /*
270
  function _resize($numWidth, $numHeight, $numQuality=95){
271
  //check for image protection
272
  if($this->_imageProtect($numWidth, $numHeight)){
273
+
274
+ // GIF image
275
  if($this->arrOriginalDetails['mime']=="image/gif"){
 
276
  $this->resResizedImage = imagecreate($numWidth, $numHeight);
277
+ }
278
+
279
+ // JPG image
280
+ else if($this->arrOriginalDetails['mime']=="image/jpeg"){
281
  $this->resResizedImage = imagecreatetruecolor($numWidth, $numHeight);
282
+ }
283
+
284
+ // PNG image
285
+ else if($this->arrOriginalDetails['mime']=="image/png"){
286
  $this->resResizedImage = imagecreatetruecolor($numWidth, $numHeight);
287
  imagecolortransparent($this->resResizedImage, imagecolorallocate($this->resResizedImage, 0, 0, 0));
288
  imagealphablending($this->resResizedImage, false);
296
  } else {
297
  imagecopyresized($this->resResizedImage, $this->resOriginalImage, 0, 0, 0, 0, $numWidth, $numHeight, $this->arrOriginalDetails[0], $this->arrOriginalDetails[1]);
298
  }
299
+
300
  //saves the image
301
  $this->saveImage($numQuality);
302
  }
313
  */
314
 
315
  function _imageProtect($numWidth, $numHeight){
316
+ if($this->boolProtect AND ($numWidth >= $this->arrOriginalDetails[0] OR $numHeight >= $this->arrOriginalDetails[1])){
317
  return 0;
318
  }
319
  return 1;
344
 
345
  function resizeToHeight($numHeight){
346
  $numWidth=(int)(($numHeight*$this->arrOriginalDetails[0])/$this->arrOriginalDetails[1]);
347
+ $this->_resize($numWidth, $numHeight, $this->numQuality);
348
  }
349
 
350
  /*
359
  function resizeToPercent($numPercent){
360
  $numWidth = (int)(($this->arrOriginalDetails[0]/100)*$numPercent);
361
  $numHeight = (int)(($this->arrOriginalDetails[1]/100)*$numPercent);
362
+ $this->_resize($numWidth, $numHeight, $this->numQuality);
363
  }
364
 
365
  /*
373
 
374
  function resizeToCustom($size){
375
  if(!is_array($size)){
376
+ $this->_resize((int)$size, (int)$size, $this->numQuality);
377
  }else{
378
+ $this->_resize((int)$size[0], (int)$size[1], $this->numQuality);
379
  }
380
  }
381
  }
readme.txt CHANGED
@@ -1,10 +1,10 @@
1
  === Resize Image After Upload ===
2
  Contributors: jepsonrae
3
- Donate link: http://www.jepsonrae.com/?utm_campaign=plugins&utm_source=wp-resize-image-after-upload&utm_medium=donate-link
4
  Tags: image, plugin, resize, upload
5
- Requires at least: 2.6
6
- Tested up to: 3.9
7
- Stable tag: 1.4.2
8
 
9
  This plugin resizes uploaded images to within a given maximum width and height after uploading, discarding the original uploaded file in the process.
10
 
@@ -31,17 +31,21 @@ The plugin uses a class originally from Jacob Wyke (www.redvodkajelly.com) and i
31
 
32
  == Changelog ==
33
 
 
 
 
 
34
  = 1.4.2 =
35
- * [update] Added ability to enter a resize value of zero (0) to prevent resizing in a particular dimension.
36
 
37
  = 1.4.1 =
38
- * [fix] Reverting code back to how it was in v1.3.0 after previous premature deployment of v1.4.0. Please use this version.
39
 
40
  = 1.4.0 =
41
- * [error] Code was deployed prematurely and should not have made its way to the live repository. Please do NOT use this version.
42
 
43
  = 1.3.0 =
44
- * [update] Added ability to set the JPEG compression quality level when JPEGs are resized. Default is 90.
45
 
46
  = 1.2.0 =
47
  * [Update] Now only runs images through the resizer if required, i.e. the image is actually larger than the max height/width.
1
  === Resize Image After Upload ===
2
  Contributors: jepsonrae
3
+ Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=3W4M254AA3KZG
4
  Tags: image, plugin, resize, upload
5
+ Requires at least: 3.5
6
+ Tested up to: 4.0
7
+ Stable tag: 1.5.0
8
 
9
  This plugin resizes uploaded images to within a given maximum width and height after uploading, discarding the original uploaded file in the process.
10
 
31
 
32
  == Changelog ==
33
 
34
+ = 1.5.0 =
35
+ * [Added] Ability to force re-compression even if resize is not required.
36
+ * [Fix] Compression quality value was not adhered to.
37
+
38
  = 1.4.2 =
39
+ * [Update] Added ability to enter a resize value of zero (0) to prevent resizing in a particular dimension.
40
 
41
  = 1.4.1 =
42
+ * [Fix] Reverting code back to how it was in v1.3.0 after previous premature deployment of v1.4.0. Please use this version.
43
 
44
  = 1.4.0 =
45
+ * [Error] Code was deployed prematurely and should not have made its way to the live repository. Please do NOT use this version.
46
 
47
  = 1.3.0 =
48
+ * [Update] Added ability to set the JPEG compression quality level when JPEGs are resized. Default is 90.
49
 
50
  = 1.2.0 =
51
  * [Update] Now only runs images through the resizer if required, i.e. the image is actually larger than the max height/width.
resize-image-after-upload.php CHANGED
@@ -3,8 +3,8 @@
3
  Plugin Name: Resize Image After Upload
4
  Plugin URI: http://www.jepsonrae.com/?utm_campaign=plugins&utm_source=wp-resize-image-after-upload&utm_medium=plugin-url
5
  Description: This plugin resizes uploaded images to a given width or height (whichever is the largest) after uploading, discarding the original uploaded file in the process.
6
- Author: Jepson Rae
7
- Version: 1.4.2
8
  Author URI: http://www.jepsonrae.com/?utm_campaign=plugins&utm_source=wp-resize-image-after-upload&utm_medium=author-url
9
 
10
 
@@ -36,7 +36,7 @@ along with this program; if not, write to the Free Software
36
  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
37
  */
38
 
39
- $PLUGIN_VERSION = '1.4.2';
40
 
41
 
42
  // Default plugin values
@@ -47,7 +47,9 @@ if(get_option('jr_resizeupload_version') != $PLUGIN_VERSION) {
47
  add_option('jr_resizeupload_height', '1200', '', 'yes');
48
  add_option('jr_resizeupload_quality', '90', '', 'yes');
49
  add_option('jr_resizeupload_resize_yesno', 'yes', '','yes');
 
50
  add_option('jr_resizeupload_convertbmp_yesno', 'no', '', 'no');
 
51
  }
52
 
53
 
@@ -93,6 +95,8 @@ function jr_uploadresize_options(){
93
  $maxheight = trim(mysql_real_escape_string($_POST['maxheight']));
94
  $quality = trim(mysql_real_escape_string($_POST['quality']));
95
  $yesno = $_POST['yesno'];
 
 
96
  $convert_bmp = $_POST['convertbmp'];
97
 
98
  // if input is empty or not an integer, use previous setting
@@ -128,6 +132,22 @@ function jr_uploadresize_options(){
128
  } // else
129
 
130
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
131
  if ($convert_bmp == 'yes') {
132
  update_option('jr_resizeupload_convertbmp_yesno','yes');
133
  } // if
@@ -147,6 +167,8 @@ function jr_uploadresize_options(){
147
  $maxheight = get_option('jr_resizeupload_height');
148
  $quality = intval(get_option('jr_resizeupload_quality'));
149
  $yesno = get_option('jr_resizeupload_resize_yesno');
 
 
150
  $convert_bmp = get_option('jr_resizeupload_convertbmp_yesno');
151
  ?>
152
 
@@ -166,7 +188,7 @@ function jr_uploadresize_options(){
166
  <h3 style="margin-top:20px;border-top:1px solid #eee;padding-top:20px;">Settings</h3>
167
  <table class="form-table">
168
  <tr>
169
- <td valign="top">Resize images:&nbsp;</td>
170
  <td valign="top">
171
  <select name="yesno" id="yesno">
172
  <option value="no" label="no" <?php echo ($yesno == 'no') ? 'selected="selected"' : ''; ?>>No</option>
@@ -174,6 +196,17 @@ function jr_uploadresize_options(){
174
  </select>
175
  </td>
176
  </tr>
 
 
 
 
 
 
 
 
 
 
 
177
 
178
  <tr>
179
  <td valign="top">Maximum width and height (pixels):&nbsp;</td>
@@ -198,6 +231,20 @@ function jr_uploadresize_options(){
198
  <br />Default value: 90</small>
199
  </td>
200
  </tr>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
201
 
202
  <!--
203
  <tr>
@@ -244,40 +291,56 @@ function jr_uploadresize_resize($array){
244
  // Include the file to carry out the resizing
245
  require_once('class.resize.php');
246
 
247
- // Get resizing limits
248
  $max_width = get_option('jr_resizeupload_width');
249
  $max_height = get_option('jr_resizeupload_height');
250
 
251
  $quality = get_option('jr_resizeupload_quality');
252
 
 
 
 
 
 
 
 
253
  $convert_bmp = get_option('jr_resizeupload_convertbmp_yesno');
254
- $convert_bmp = ($convert_bmp=='yes') ? true : false;
255
 
256
 
257
- // Get original image sizes
258
  $original_info = getimagesize($array['file']);
259
  $original_width = $original_info[0];
260
  $original_height = $original_info[1];
 
261
  $is_bitmap = ($array['type'] == 'image/bmp') ? true : false;
262
 
 
 
 
 
 
 
 
 
 
263
 
264
- // Perform the resize only if required, i.e. the image is larger than the max sizes
265
- if( $original_width > $max_width ||
266
- $original_height > $max_height ||
267
- ($is_bitmap && $convert_bmp)
268
- ) {
269
-
270
- //Resize by width
271
- if($original_width > $original_height && $max_width != 0) {
272
- $objResize = new RVJ_ImageResize($array['file'], $array['file'], 'W', $max_width, true, $quality);
273
 
274
- }
275
-
276
- //Resize by height
277
- else if($max_height != 0) {
278
- $objResize = new RVJ_ImageResize($array['file'], $array['file'], 'H', $max_height, true, $quality);
 
 
279
  }
280
- }
281
  } // if(...)
282
 
283
  return $array;
3
  Plugin Name: Resize Image After Upload
4
  Plugin URI: http://www.jepsonrae.com/?utm_campaign=plugins&utm_source=wp-resize-image-after-upload&utm_medium=plugin-url
5
  Description: This plugin resizes uploaded images to a given width or height (whichever is the largest) after uploading, discarding the original uploaded file in the process.
6
+ Author: JEPSONRAE
7
+ Version: 1.5.0
8
  Author URI: http://www.jepsonrae.com/?utm_campaign=plugins&utm_source=wp-resize-image-after-upload&utm_medium=author-url
9
 
10
 
36
  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
37
  */
38
 
39
+ $PLUGIN_VERSION = '1.5.0';
40
 
41
 
42
  // Default plugin values
47
  add_option('jr_resizeupload_height', '1200', '', 'yes');
48
  add_option('jr_resizeupload_quality', '90', '', 'yes');
49
  add_option('jr_resizeupload_resize_yesno', 'yes', '','yes');
50
+ add_option('jr_resizeupload_recompress_yesno', 'no', '','yes');
51
  add_option('jr_resizeupload_convertbmp_yesno', 'no', '', 'no');
52
+ add_option('jr_resizeupload_convertpng_yesno', 'no', '', 'no');
53
  }
54
 
55
 
95
  $maxheight = trim(mysql_real_escape_string($_POST['maxheight']));
96
  $quality = trim(mysql_real_escape_string($_POST['quality']));
97
  $yesno = $_POST['yesno'];
98
+ $recompress_yesno = $_POST['recompress_yesno'];
99
+ $convert_png = $_POST['convertpng'];
100
  $convert_bmp = $_POST['convertbmp'];
101
 
102
  // if input is empty or not an integer, use previous setting
132
  } // else
133
 
134
 
135
+ if ($recompress_yesno == 'yes') {
136
+ update_option('jr_resizeupload_recompress_yesno','yes');
137
+ } // if
138
+ else {
139
+ update_option('jr_resizeupload_recompress_yesno','no');
140
+ } // else
141
+
142
+
143
+ if ($convert_png == 'yes') {
144
+ update_option('jr_resizeupload_convertpng_yesno','yes');
145
+ } // if
146
+ else {
147
+ update_option('jr_resizeupload_convertpng_yesno','no');
148
+ } // else
149
+
150
+
151
  if ($convert_bmp == 'yes') {
152
  update_option('jr_resizeupload_convertbmp_yesno','yes');
153
  } // if
167
  $maxheight = get_option('jr_resizeupload_height');
168
  $quality = intval(get_option('jr_resizeupload_quality'));
169
  $yesno = get_option('jr_resizeupload_resize_yesno');
170
+ $recompress_yesno = get_option('jr_resizeupload_recompress_yesno');
171
+ $convert_png = get_option('jr_resizeupload_convertpng_yesno');
172
  $convert_bmp = get_option('jr_resizeupload_convertbmp_yesno');
173
  ?>
174
 
188
  <h3 style="margin-top:20px;border-top:1px solid #eee;padding-top:20px;">Settings</h3>
189
  <table class="form-table">
190
  <tr>
191
+ <td valign="top">Re-size images:&nbsp;</td>
192
  <td valign="top">
193
  <select name="yesno" id="yesno">
194
  <option value="no" label="no" <?php echo ($yesno == 'no') ? 'selected="selected"' : ''; ?>>No</option>
196
  </select>
197
  </td>
198
  </tr>
199
+
200
+ <tr>
201
+ <td valign="top">Re-compress even if no resize required:&nbsp;</td>
202
+ <td valign="top">
203
+ <select name="recompress_yesno" id="yesno">
204
+ <option value="no" label="no" <?php echo ($recompress_yesno == 'no') ? 'selected="selected"' : ''; ?>>No</option>
205
+ <option value="yes" label="yes" <?php echo ($recompress_yesno == 'yes') ? 'selected="selected"' : ''; ?>>Yes</option>
206
+ </select>
207
+ <br /><small>Normally only images requiring resizing will be re-compressed.</small>
208
+ </td>
209
+ </tr>
210
 
211
  <tr>
212
  <td valign="top">Maximum width and height (pixels):&nbsp;</td>
231
  <br />Default value: 90</small>
232
  </td>
233
  </tr>
234
+
235
+ <!--
236
+ <tr>
237
+ <td valign="top">Convert PNGs to JPEGs:&nbsp;</td>
238
+ <td valign="top">
239
+ <select id="convert-png" name="convertpng">
240
+ <option value="no" <?php if($convert_png == 'no') : ?>selected<?php endif; ?>>No</option>
241
+ <option value="yes" <?php if($convert_png == 'yes') : ?>selected<?php endif; ?>>Yes</option>
242
+ </select>
243
+ <br /><small>When a PNG is uploaded, it will automatically be converted to a JPEG
244
+ <br />Selecting 'No' will <strong>not</strong> prevent PNGs from being resized</small>
245
+ </td>
246
+ </tr>
247
+ -->
248
 
249
  <!--
250
  <tr>
291
  // Include the file to carry out the resizing
292
  require_once('class.resize.php');
293
 
294
+ // Get resizing limits
295
  $max_width = get_option('jr_resizeupload_width');
296
  $max_height = get_option('jr_resizeupload_height');
297
 
298
  $quality = get_option('jr_resizeupload_quality');
299
 
300
+ $recompress_yesno = get_option('jr_resizeupload_recompress_yesno');
301
+ $recompress_yesno = ($recompress_yesno=='yes') ? true : false;
302
+ $protect_image = ($recompress_yesno ? false : true); // opposite of recompress_yesno
303
+
304
+ $convert_png = get_option('jr_resizeupload_convertpng_yesno');
305
+ $convert_png = ($convert_png=='yes') ? true : false;
306
+
307
  $convert_bmp = get_option('jr_resizeupload_convertbmp_yesno');
308
+ $convert_bmp = ($convert_bmp=='yes') ? true : false;
309
 
310
 
311
+ // Get original image sizes
312
  $original_info = getimagesize($array['file']);
313
  $original_width = $original_info[0];
314
  $original_height = $original_info[1];
315
+ $is_png = ($array['type'] == 'image/png') ? true : false;
316
  $is_bitmap = ($array['type'] == 'image/bmp') ? true : false;
317
 
318
+
319
+
320
+ // Perform resizing operations if reduction is required
321
+ if($original_width >= $max_width || $original_height >= $max_height) {
322
+
323
+ //Resize by width
324
+ if($original_width > $original_height && $max_width != 0) {
325
+ $objResize = new RVJ_ImageResize($array['file'], $array['file'], 'W', $max_width, $protect_image, $quality);
326
+ }
327
 
328
+ //Resize by height
329
+ else if($max_height != 0) {
330
+ $objResize = new RVJ_ImageResize($array['file'], $array['file'], 'H', $max_height, $protect_image, $quality);
331
+ }
332
+ }
333
+
 
 
 
334
 
335
+ // Resizing is not required, but still need to re-compress to desired quality and filetype
336
+ else if($recompress_yesno || ($is_png && $convert_png) || ($is_bitmap && $convert_bmp)) {
337
+ $objResize = new RVJ_ImageResize($array['file'], $array['file'], 'P', 100, $protect_image, $quality);
338
+ }
339
+
340
+ else {
341
+ // no resize/recompress
342
  }
343
+
344
  } // if(...)
345
 
346
  return $array;