Resize Image After Upload - Version 1.4.2

Version Description

  • [update] Added ability to enter a resize value of zero (0) to prevent resizing in a particular dimension.
Download this release

Release Info

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

Code changes from version 1.4.1 to 1.4.2

Files changed (2) hide show
  1. readme.txt +33 -30
  2. resize-image-after-upload.php +64 -19
readme.txt CHANGED
@@ -1,35 +1,38 @@
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.5.2
7
- Stable tag: 1.4.1
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
-
11
- == Description ==
12
-
13
  This plugin resizes uploaded images to within a given maximum width and height after uploading, discarding the original uploaded file in the process. The original image is destroyed to save space, and unfortunately EXIF dataa is lost due to this process.
14
 
15
  The requirement for this plugin is due to the fact that digital cameras and mobile phones now take pictures of over 4000x3000 pixels in dimension, and can range in size from a few MB, to 20MB. Having these original images stored on the server can quickly consume up valuable disk space. This plugin will reduce the size of the uploaded image at point of upload; then either WordPress or some other resize script such as TimThumb can then further reduce the image size to suit positioning in the website theme.
16
-
17
  This plugin uses standard PHP resizing functions so resizing is not on par with what you could produce in Photoshop. However for the large majority of cases, this is not noticeable in the slightest.
18
-
19
- The plugin uses a class originally from Jacob Wyke (www.redvodkajelly.com) and is a direct update of another plugin called Resize at Upload which is no longer maintained.
20
-
21
- == Installation ==
22
-
23
- 1. Upload the plugin 'resize-image-after-upload' to the '/wp-content/plugins/' directory
24
- 2. Activate the plugin through the 'Plugins' menu in WordPress
25
- 3. Activate the resize function and set maximum width and height through the 'Settings > Resize Image Upload' menu in WordPress
26
- 4. Upload images while writing posts and pages.
27
-
28
- == Screenshots ==
29
-
30
- 1. Full preview of the settings screen
31
-
32
- == Changelog ==
 
 
 
33
 
34
  = 1.4.1 =
35
  * [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,7 +42,7 @@ The plugin uses a class originally from Jacob Wyke (www.redvodkajelly.com) and i
39
 
40
  = 1.3.0 =
41
  * [update] Added ability to set the JPEG compression quality level when JPEGs are resized. Default is 90.
42
-
43
  = 1.2.0 =
44
  * [Update] Now only runs images through the resizer if required, i.e. the image is actually larger than the max height/width.
45
 
@@ -48,7 +51,7 @@ The plugin uses a class originally from Jacob Wyke (www.redvodkajelly.com) and i
48
  * [Fix] Adds default option for max-height value.
49
  * [Update] Updated the screenshot to include new maximum height field.
50
  * [Update] Increased the default maximum height and width to 1200px each.
51
-
52
  = 1.1.0 =
53
  * [Update] Added ability to set maximum height (thanks @Wonderm00n).
54
 
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
+
11
+ == Description ==
12
+
13
  This plugin resizes uploaded images to within a given maximum width and height after uploading, discarding the original uploaded file in the process. The original image is destroyed to save space, and unfortunately EXIF dataa is lost due to this process.
14
 
15
  The requirement for this plugin is due to the fact that digital cameras and mobile phones now take pictures of over 4000x3000 pixels in dimension, and can range in size from a few MB, to 20MB. Having these original images stored on the server can quickly consume up valuable disk space. This plugin will reduce the size of the uploaded image at point of upload; then either WordPress or some other resize script such as TimThumb can then further reduce the image size to suit positioning in the website theme.
16
+
17
  This plugin uses standard PHP resizing functions so resizing is not on par with what you could produce in Photoshop. However for the large majority of cases, this is not noticeable in the slightest.
18
+
19
+ The plugin uses a class originally from Jacob Wyke (www.redvodkajelly.com) and is a direct update of another plugin called Resize at Upload which is no longer maintained.
20
+
21
+ == Installation ==
22
+
23
+ 1. Upload the plugin 'resize-image-after-upload' to the '/wp-content/plugins/' directory
24
+ 2. Activate the plugin through the 'Plugins' menu in WordPress
25
+ 3. Activate the resize function and set maximum width and height through the 'Settings > Resize Image Upload' menu in WordPress
26
+ 4. Upload images while writing posts and pages.
27
+
28
+ == Screenshots ==
29
+
30
+ 1. Full preview of the settings screen
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.
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.
48
 
51
  * [Fix] Adds default option for max-height value.
52
  * [Update] Updated the screenshot to include new maximum height field.
53
  * [Update] Increased the default maximum height and width to 1200px each.
54
+
55
  = 1.1.0 =
56
  * [Update] Added ability to set maximum height (thanks @Wonderm00n).
57
 
resize-image-after-upload.php CHANGED
@@ -4,7 +4,7 @@ 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.1
8
  Author URI: http://www.jepsonrae.com/?utm_campaign=plugins&utm_source=wp-resize-image-after-upload&utm_medium=author-url
9
 
10
 
@@ -36,17 +36,18 @@ 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.1';
40
 
41
 
42
  // Default plugin values
43
  if(get_option('jr_resizeupload_version') != $PLUGIN_VERSION) {
44
 
45
- add_option('jr_resizeupload_version', $PLUGIN_VERSION, '','yes');
46
- add_option('jr_resizeupload_width', '1200', '', 'yes');
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
  }
51
 
52
 
@@ -92,6 +93,7 @@ function jr_uploadresize_options(){
92
  $maxheight = trim(mysql_real_escape_string($_POST['maxheight']));
93
  $quality = trim(mysql_real_escape_string($_POST['quality']));
94
  $yesno = $_POST['yesno'];
 
95
 
96
  // if input is empty or not an integer, use previous setting
97
  if ($maxwidth == '' || ctype_digit(strval($maxwidth)) == FALSE) {
@@ -124,6 +126,16 @@ function jr_uploadresize_options(){
124
  else {
125
  update_option('jr_resizeupload_resize_yesno','no');
126
  } // else
 
 
 
 
 
 
 
 
 
 
127
 
128
  echo('<div id="message" class="updated fade"><p><strong>Options have been updated.</strong></p></div>');
129
  } // if
@@ -133,16 +145,19 @@ function jr_uploadresize_options(){
133
  // get options and show settings form
134
  $maxwidth = get_option('jr_resizeupload_width');
135
  $maxheight = get_option('jr_resizeupload_height');
136
- $quality = get_option('jr_resizeupload_quality');
137
  $yesno = get_option('jr_resizeupload_resize_yesno');
 
138
  ?>
139
 
140
  <div class="wrap">
141
  <form method="post" accept-charset="utf-8">
142
 
143
  <h2>Resize Image After Upload Options</h2>
144
- <p>This plugin resizes uploaded images to given maximum width and/or height after uploading, discarding the original uploaded file in the process.
145
  You can set the max width and max height, and images (JPEG, PNG or GIF) will be resized automatically after they are uploaded.</p>
 
 
146
 
147
  <p>Your file will be resized, there will not be a copy or backup with the original size.</p>
148
 
@@ -165,7 +180,8 @@ function jr_uploadresize_options(){
165
  <td valign="top">
166
  <input type="text" name="maxwidth" size="7" id="maxwidth" value="<?php echo $maxwidth; ?>" /> px-wide
167
  <br /><input type="text" name="maxheight" size="7" id="maxheight" value="<?php echo $maxheight; ?>" /> px-high
168
- <br /><small>Integer pixel value (e.g. 1200)</small>
 
169
  <br /><small>Recommended value: 1200</small>
170
  </td>
171
  </tr>
@@ -173,15 +189,33 @@ function jr_uploadresize_options(){
173
  <tr>
174
  <td valign="top">Compression quality (for JPEGs):&nbsp;</td>
175
  <td valign="top">
176
- <input type="text" name="quality" size="5" id="maxwidth" value="<?php echo $quality; ?>" />
177
- <br /><small>Integer between 0 (low quality, smallest files) and 100 (best quality, largest files)</small>
178
- <br /><small>Recommended value: 90</small>
 
 
 
 
179
  </td>
180
  </tr>
181
-
 
 
 
 
 
 
 
 
 
 
 
 
 
182
  </table>
183
 
184
  <p class="submit" style="margin-top:20px;border-top:1px solid #eee;padding-top:20px;">
 
185
  <input type="hidden" name="action" value="update" />
186
  <input id="submit" name="jr_options_update" class="button button-primary" type="submit" value="Update Options">
187
  </p>
@@ -202,7 +236,9 @@ function jr_uploadresize_resize($array){
202
  if(
203
  $array['type'] == 'image/jpeg' ||
204
  $array['type'] == 'image/gif' ||
205
- $array['type'] == 'image/png')
 
 
206
  {
207
 
208
  // Include the file to carry out the resizing
@@ -213,27 +249,36 @@ function jr_uploadresize_resize($array){
213
  $max_height = get_option('jr_resizeupload_height');
214
 
215
  $quality = get_option('jr_resizeupload_quality');
 
 
 
 
216
 
217
  // Get original image sizes
218
  $original_info = getimagesize($array['file']);
219
  $original_width = $original_info[0];
220
  $original_height = $original_info[1];
 
 
221
 
222
  // Perform the resize only if required, i.e. the image is larger than the max sizes
223
- if($original_width > $max_width || $original_height > $max_height) {
 
 
 
224
 
225
  //Resize by width
226
- if($original_width > $original_height) {
227
  $objResize = new RVJ_ImageResize($array['file'], $array['file'], 'W', $max_width, true, $quality);
228
 
229
  }
230
 
231
  //Resize by height
232
- else {
233
  $objResize = new RVJ_ImageResize($array['file'], $array['file'], 'H', $max_height, true, $quality);
234
  }
235
  }
236
- }
237
 
238
  return $array;
239
  } // function jr_uploadresize_resize($array){
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
  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
43
  if(get_option('jr_resizeupload_version') != $PLUGIN_VERSION) {
44
 
45
+ add_option('jr_resizeupload_version', $PLUGIN_VERSION, '','yes');
46
+ add_option('jr_resizeupload_width', '1200', '', 'yes');
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
  $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
99
  if ($maxwidth == '' || ctype_digit(strval($maxwidth)) == FALSE) {
126
  else {
127
  update_option('jr_resizeupload_resize_yesno','no');
128
  } // else
129
+
130
+
131
+ if ($convert_bmp == 'yes') {
132
+ update_option('jr_resizeupload_convertbmp_yesno','yes');
133
+ } // if
134
+ else {
135
+ update_option('jr_resizeupload_convertbmp_yesno','no');
136
+ } // else
137
+
138
+
139
 
140
  echo('<div id="message" class="updated fade"><p><strong>Options have been updated.</strong></p></div>');
141
  } // if
145
  // get options and show settings form
146
  $maxwidth = get_option('jr_resizeupload_width');
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
 
153
  <div class="wrap">
154
  <form method="post" accept-charset="utf-8">
155
 
156
  <h2>Resize Image After Upload Options</h2>
157
+ <p>This plugin resizes uploaded images to given maximum width and/or height after uploading, discarding the original uploaded file in the process.
158
  You can set the max width and max height, and images (JPEG, PNG or GIF) will be resized automatically after they are uploaded.</p>
159
+
160
+ <!-- <p>If 'Convert BMPs to JPEGs' is enabled, then BMP files will also be resized.</p> -->
161
 
162
  <p>Your file will be resized, there will not be a copy or backup with the original size.</p>
163
 
180
  <td valign="top">
181
  <input type="text" name="maxwidth" size="7" id="maxwidth" value="<?php echo $maxwidth; ?>" /> px-wide
182
  <br /><input type="text" name="maxheight" size="7" id="maxheight" value="<?php echo $maxheight; ?>" /> px-high
183
+ <br /><small>Integer pixel value (e.g. 1200). </small>
184
+ <br /><small>Set to zero (0) to prevent resizing in that dimension.</small>
185
  <br /><small>Recommended value: 1200</small>
186
  </td>
187
  </tr>
189
  <tr>
190
  <td valign="top">Compression quality (for JPEGs):&nbsp;</td>
191
  <td valign="top">
192
+ <select id="quality" name="quality">
193
+ <?php for($i=1; $i<=100; $i++) : ?>
194
+ <option value="<?php echo $i; ?>" <?php if($quality == $i) : ?>selected<?php endif; ?>><?php echo $i; ?></option>
195
+ <?php endfor; ?>
196
+ </select>
197
+ <br /><small>Integer between 0 (low quality, smallest files) and 100 (best quality, largest files)
198
+ <br />Default value: 90</small>
199
  </td>
200
  </tr>
201
+
202
+ <!--
203
+ <tr>
204
+ <td valign="top">Convert BMPs to JPEGs and resize:&nbsp;</td>
205
+ <td valign="top">
206
+ <select id="convert-bmp" name="convertbmp">
207
+ <option value="no" <?php if($convert_bmp == 'no') : ?>selected<?php endif; ?>>No</option>
208
+ <option value="yes" <?php if($convert_bmp == 'yes') : ?>selected<?php endif; ?>>Yes</option>
209
+ </select>
210
+ <br /><small>When a BMP is uploaded, it will automatically be converted to a JPEG
211
+ <br />Selecting 'No' will prevent BMPs from being resized</small>
212
+ </td>
213
+ </tr>
214
+ -->
215
  </table>
216
 
217
  <p class="submit" style="margin-top:20px;border-top:1px solid #eee;padding-top:20px;">
218
+ <input type="hidden" id="convert-bmp" name="convertbmp" value="no" />
219
  <input type="hidden" name="action" value="update" />
220
  <input id="submit" name="jr_options_update" class="button button-primary" type="submit" value="Update Options">
221
  </p>
236
  if(
237
  $array['type'] == 'image/jpeg' ||
238
  $array['type'] == 'image/gif' ||
239
+ $array['type'] == 'image/png' ||
240
+ $array['type'] == 'image/bmp'
241
+ )
242
  {
243
 
244
  // Include the file to carry out the resizing
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;
284
  } // function jr_uploadresize_resize($array){