Resize Image After Upload - Version 1.1.0

Version Description

  • [Update] Added ability to set maximum height (thanks @Wonderm00n).
Download this release

Release Info

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

Code changes from version 1.0.1 to 1.1.0

Files changed (2) hide show
  1. readme.txt +15 -22
  2. resize-image-after-upload.php +32 -15
readme.txt CHANGED
@@ -1,22 +1,20 @@
1
  === Resize Image After Upload ===
2
  Contributors: jepsonrae
3
- Donate link: http://www.jepsonrae.com/?utm_medium=plugins&utm_campaign=referrals&utm_source=wp-resize-image-after-upload
4
  Tags: image, plugin, resize, upload
5
  Requires at least: 2.6
6
- Tested up to: 3.4.2
7
- Stable tag: 1.0.1
8
- License: GPLv2 or later
9
- License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
11
- This plugin resizes uploaded images to a given width after uploading, discarding the original uploaded file in the process.
12
 
13
  == Description ==
14
 
15
- The plugin affects the uploaded image after it is uploaded. Straight after it is uploaded, it it resized physically to the given width. There is no original image left, nor a backup made. This is deliberate to prevent wasted server space from enormous image files being stored. Unfortunately, this causes EXIF information to be lost.
16
-
17
- A lot of WordPress users or developers who use WordPress as a CMS and want to configure it for easy use, would like to have an option to resize uploaded images. Some images come straight from digital cameras and exceed 4000 pixels in width. So it would be nice to reduce that to the max width you use inside your WordPress theme.
18
 
19
- If you would like to keep control of perfect sharpness when resizing, it would be better use photo editing tools on your computer, not a script like this.
20
 
21
  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.
22
 
@@ -24,25 +22,20 @@ The plugin uses a class originally from Jacob Wyke (www.redvodkajelly.com) and i
24
 
25
  1. Upload the plugin 'resize-image-after-upload' to the '/wp-content/plugins/' directory
26
  2. Activate the plugin through the 'Plugins' menu in WordPress
27
- 3. Make your settings through the 'Settings > Resize Image Upload' menu in WordPress
28
  4. Upload images while writing posts and pages.
29
 
30
  == Screenshots ==
31
 
32
  1. Full preview of the settings screen
33
-
34
- == Frequently Asked Questions ==
35
-
36
- Q. Why not reduce images in height?
37
- A. The reason I wrote the plugin was to stop breaking the layout with images that are to large. Height is not always an issue. Maybe in future this option will be added.
38
-
39
- Q. Does it keep my EXIF data?
40
- A. No. Although it is programmatically possible to extract that data first and put it somewhere in the metadata, which is not currently implemented, but a possibility for future releases.
41
 
42
- == Changelog ==
 
 
 
43
 
44
  = 1.0.1 =
45
- * Update to read me, no feature updates unfortunately
46
 
47
  = 1.0.0 =
48
- * Created initial plugin.
1
  === Resize Image After Upload ===
2
  Contributors: jepsonrae
3
+ Donate link: http://www.jepsonrae.com/
4
  Tags: image, plugin, resize, upload
5
  Requires at least: 2.6
6
+ Tested up to: 3.5.0
7
+ Stable tag: 1.1.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
 
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 data 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
 
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.1.0 =
35
+ * [Update] Added ability to set maximum height (thanks @Wonderm00n).
36
 
37
  = 1.0.1 =
38
+ * [Update] Update to read me, no feature updates unfortunately.
39
 
40
  = 1.0.0 =
41
+ * [Added] Initial release.
resize-image-after-upload.php CHANGED
@@ -1,11 +1,11 @@
1
  <?php
2
  /*
3
  Plugin Name: Resize Image After Upload
4
- Plugin URI: http://www.jepsonrae.com/?utm_medium=plugins&utm_campaign=referrals&utm_source=wp-resize-image-after-upload
5
- Description: This plugin resizes uploaded images to a given width after uploading, discarding the original uploaded file in the process.
6
  Author: Jepson+Rae
7
- Version: 1.0.1
8
- Author URI: http://www.jepsonrae.com/?utm_medium=plugins&utm_campaign=referrals&utm_source=wp-resize-image-after-upload
9
 
10
 
11
 
@@ -38,8 +38,9 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
38
 
39
  $version = get_option('jr_resizeupload_version');
40
  if ($version == '') {
41
- add_option('jr_resizeupload_version','1.0','Version of the plugin Resize After Image Upload','yes');
42
- add_option('jr_resizeupload_width','1000','Resize image to this width','yes');
 
43
  add_option('jr_resizeupload_resize_yesno','yes','Resize image if yes (set to no instead of unloading the plugin)','yes');
44
  } // if
45
 
@@ -63,14 +64,19 @@ function jr_uploadresize_options_page(){
63
  function jr_uploadresize_options(){
64
  if (isset($_POST['jr_options_update'])) {
65
  $maxwidth = trim(mysql_real_escape_string($_POST['maxwidth']));
 
66
  $yesno = $_POST['yesno'];
67
 
68
  // if input is empty or not an integer, use previous setting
69
  if ($maxwidth == '' OR ctype_digit(strval($maxwidth)) == FALSE) {
70
  $maxwidth = get_option('jr_resizeupload_width');
71
  } // if
 
 
 
72
 
73
  update_option('jr_resizeupload_width',$maxwidth);
 
74
 
75
  if ($yesno == 'yes') {
76
  update_option('jr_resizeupload_resize_yesno','yes');
@@ -86,6 +92,7 @@ function jr_uploadresize_options(){
86
 
87
  // get options and show settings form
88
  $maxwidth = get_option('jr_resizeupload_width');
 
89
  $yesno = get_option('jr_resizeupload_resize_yesno');
90
 
91
 
@@ -93,8 +100,8 @@ function jr_uploadresize_options(){
93
  echo('<form method="post" accept-charset="utf-8">');
94
 
95
  echo('<h2>Resize Image After Upload Options</h2>');
96
- echo('<p>This plugin resizes uploaded images to a given width after uploading, discarding the original uploaded file in the process.
97
- You can set the max width, and images (JPEG, PNG or GIF) will be resized automatically after they are uploaded.</p>');
98
 
99
  echo('<p>Your file will be resized, there will not be a copy or backup with the original size.</p>');
100
 
@@ -115,10 +122,13 @@ function jr_uploadresize_options(){
115
  </tr>
116
 
117
  <tr>
118
- <td>Max width:&nbsp;</td>
119
  <td>
120
- <input type="text" name="maxwidth" size="10" id="maxwidth" value="'.$maxwidth.'" /><br />
121
- <small>Enter a valid max width in pixels (e.g. 500).</small>
 
 
 
122
  </td>
123
  </tr>
124
 
@@ -142,9 +152,16 @@ function jr_uploadresize_resize($array){
142
  // there is a file to handle, so include the class and get the variables
143
  require_once('class.resize.php');
144
  $maxwidth = get_option('jr_resizeupload_width');
145
- $objResize = new RVJ_ImageResize($array['file'], $array['file'], 'W', $maxwidth);
 
 
 
 
 
 
 
 
 
146
  } // if
147
  return $array;
148
- } // function
149
-
150
- ?>
1
  <?php
2
  /*
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.1.0
8
+ Author URI: http://www.jepsonrae.com/?utm_campaign=plugins&utm_source=wp-resize-image-after-upload&utm_medium=author-url
9
 
10
 
11
 
38
 
39
  $version = get_option('jr_resizeupload_version');
40
  if ($version == '') {
41
+ add_option('jr_resizeupload_version','1.1.0','Version of the plugin Resize After Image Upload','yes');
42
+ add_option('jr_resizeupload_width','1000','Resize image to this maximum width','yes');
43
+ add_option('jr_resizeupload_height','1000','Resize image to this maximum height','yes');
44
  add_option('jr_resizeupload_resize_yesno','yes','Resize image if yes (set to no instead of unloading the plugin)','yes');
45
  } // if
46
 
64
  function jr_uploadresize_options(){
65
  if (isset($_POST['jr_options_update'])) {
66
  $maxwidth = trim(mysql_real_escape_string($_POST['maxwidth']));
67
+ $maxheight = trim(mysql_real_escape_string($_POST['maxheight']));
68
  $yesno = $_POST['yesno'];
69
 
70
  // if input is empty or not an integer, use previous setting
71
  if ($maxwidth == '' OR ctype_digit(strval($maxwidth)) == FALSE) {
72
  $maxwidth = get_option('jr_resizeupload_width');
73
  } // if
74
+ if ($maxheight == '' OR ctype_digit(strval($maxheight)) == FALSE) {
75
+ $maxheight = get_option('jr_resizeupload_height');
76
+ } // if
77
 
78
  update_option('jr_resizeupload_width',$maxwidth);
79
+ update_option('jr_resizeupload_height',$maxheight);
80
 
81
  if ($yesno == 'yes') {
82
  update_option('jr_resizeupload_resize_yesno','yes');
92
 
93
  // get options and show settings form
94
  $maxwidth = get_option('jr_resizeupload_width');
95
+ $maxheight = get_option('jr_resizeupload_height');
96
  $yesno = get_option('jr_resizeupload_resize_yesno');
97
 
98
 
100
  echo('<form method="post" accept-charset="utf-8">');
101
 
102
  echo('<h2>Resize Image After Upload Options</h2>');
103
+ echo('<p>This plugin resizes uploaded images to given maximum width and/or height after uploading, discarding the original uploaded file in the process.
104
+ You can set the max width and max height, and images (JPEG, PNG or GIF) will be resized automatically after they are uploaded.</p>');
105
 
106
  echo('<p>Your file will be resized, there will not be a copy or backup with the original size.</p>');
107
 
122
  </tr>
123
 
124
  <tr>
125
+ <td>Max width x height:&nbsp;</td>
126
  <td>
127
+ <input type="text" name="maxwidth" size="10" id="maxwidth" value="'.$maxwidth.'" />
128
+ x
129
+ <input type="text" name="maxheight" size="10" id="maxheight" value="'.$maxheight.'" />
130
+ <br />
131
+ <small>Enter valid max width and height in pixels (e.g. 500).</small>
132
  </td>
133
  </tr>
134
 
152
  // there is a file to handle, so include the class and get the variables
153
  require_once('class.resize.php');
154
  $maxwidth = get_option('jr_resizeupload_width');
155
+ $maxheight = get_option('jr_resizeupload_height');
156
+ //$objResize = new RVJ_ImageResize($array['file'], $array['file'], 'W', $maxwidth);
157
+ $info=getimagesize($array['file']);
158
+ if ($info[0]>$info[1]) {
159
+ //Resize by width
160
+ $objResize = new RVJ_ImageResize($array['file'], $array['file'], 'W', $maxwidth);
161
+ } else {
162
+ //Resize by height
163
+ $objResize = new RVJ_ImageResize($array['file'], $array['file'], 'H', $maxheight);
164
+ }
165
  } // if
166
  return $array;
167
+ } // function