Version Description
Minor maintenance release:
- [Fix] Correcting an error in the documentation.
Download this release
Release Info
Developer | jepsonrae |
Plugin | Resize Image After Upload |
Version | 1.6.2 |
Comparing to | |
See all releases |
Code changes from version 1.6.1 to 1.6.2
- readme.txt +9 -4
- resize-image-after-upload.php +126 -126
readme.txt
CHANGED
@@ -3,8 +3,8 @@ Contributors: iamphilrae
|
|
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
|
5 |
Requires at least: 3.5
|
6 |
-
Tested up to: 4.
|
7 |
-
Stable tag: 1.6.
|
8 |
|
9 |
Simple plugin to automatically resize uploaded images to within specified maximum width and height. Also has option to force recompression of JPEGs.
|
10 |
|
@@ -12,7 +12,7 @@ Simple plugin to automatically resize uploaded images to within specified maximu
|
|
12 |
|
13 |
This plugin automatically resizes uploaded images (JPEG, GIF, and PNG) 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: the resizing/recompression process will discard the original uploaded file including EXIF data.
|
18 |
|
@@ -33,6 +33,11 @@ This plugin uses standard PHP image resizing functions and will require a high a
|
|
33 |
|
34 |
== Changelog ==
|
35 |
|
|
|
|
|
|
|
|
|
|
|
36 |
= 1.6.1 =
|
37 |
Fix a few edge case bugs, I go and break the main functionality - that's life! This is a maintenance release to fix a bug.
|
38 |
|
@@ -70,7 +75,7 @@ This is a major maintenance release to squash a few long outstanding bugs.
|
|
70 |
* [Fix] Corrected functionality that sets default plugin options if the plugin version number changes.
|
71 |
* [Fix] Adds default option for max-height value.
|
72 |
* [Update] Updated the screenshot to include new maximum height field.
|
73 |
-
* [Update] Increased the default maximum height and width to 1200px each.
|
74 |
|
75 |
= 1.1 =
|
76 |
* [Update] Added ability to set maximum height (thanks @Wonderm00n).
|
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
|
5 |
Requires at least: 3.5
|
6 |
+
Tested up to: 4.1
|
7 |
+
Stable tag: 1.6.2
|
8 |
|
9 |
Simple plugin to automatically resize uploaded images to within specified maximum width and height. Also has option to force recompression of JPEGs.
|
10 |
|
12 |
|
13 |
This plugin automatically resizes uploaded images (JPEG, GIF, and PNG) 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: the resizing/recompression process will discard the original uploaded file including EXIF data.
|
18 |
|
33 |
|
34 |
== Changelog ==
|
35 |
|
36 |
+
= 1.6.2 =
|
37 |
+
Minor maintenance release:
|
38 |
+
|
39 |
+
* [Fix] Correcting an error in the documentation.
|
40 |
+
|
41 |
= 1.6.1 =
|
42 |
Fix a few edge case bugs, I go and break the main functionality - that's life! This is a maintenance release to fix a bug.
|
43 |
|
75 |
* [Fix] Corrected functionality that sets default plugin options if the plugin version number changes.
|
76 |
* [Fix] Adds default option for max-height value.
|
77 |
* [Update] Updated the screenshot to include new maximum height field.
|
78 |
+
* [Update] Increased the default maximum height and width to 1200px each.
|
79 |
|
80 |
= 1.1 =
|
81 |
* [Update] Added ability to set maximum height (thanks @Wonderm00n).
|
resize-image-after-upload.php
CHANGED
@@ -4,16 +4,16 @@ 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: iamphilrae
|
7 |
-
Version: 1.6.
|
8 |
Author URI: http://www.philr.ae/
|
9 |
|
10 |
-
Copyright (C)
|
11 |
-
|
12 |
|
13 |
Includes hints and code by:
|
14 |
Huiz.net (www.huiz.net)
|
15 |
Jacob Wyke (www.redvodkajelly.com)
|
16 |
-
Paolo Tresso / Pixline (http://pixline.net)
|
17 |
|
18 |
This program is free software; you can redistribute it and/or
|
19 |
modify it under the terms of the GNU General Public License
|
@@ -30,7 +30,7 @@ along with this program; if not, write to the Free Software
|
|
30 |
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
31 |
*/
|
32 |
|
33 |
-
$PLUGIN_VERSION = '1.6.
|
34 |
$DEBUG_LOGGER = false;
|
35 |
|
36 |
|
@@ -51,50 +51,50 @@ if(get_option('jr_resizeupload_version') != $PLUGIN_VERSION) {
|
|
51 |
|
52 |
|
53 |
// Hook in the options page
|
54 |
-
add_action('admin_menu', 'jr_uploadresize_options_page');
|
55 |
|
56 |
// Hook the function to the upload handler
|
57 |
add_action('wp_handle_upload', 'jr_uploadresize_resize');
|
58 |
|
59 |
|
60 |
|
61 |
-
|
62 |
/**
|
63 |
* Add the options page
|
64 |
*/
|
65 |
function jr_uploadresize_options_page(){
|
66 |
if(function_exists('add_options_page')){
|
67 |
add_options_page(
|
68 |
-
'Resize Image After Upload',
|
69 |
-
'Resize Image Upload',
|
70 |
-
'manage_options',
|
71 |
-
'resize-after-upload',
|
72 |
'jr_uploadresize_options'
|
73 |
);
|
74 |
-
}
|
75 |
-
} // function jr_uploadresize_options_page(){
|
76 |
|
77 |
|
78 |
|
79 |
-
/**
|
80 |
* Define the Options page for the plugin
|
81 |
*/
|
82 |
function jr_uploadresize_options(){
|
83 |
|
84 |
if(isset($_POST['jr_options_update'])) {
|
85 |
-
|
86 |
$resizing_enabled = trim(esc_sql($_POST['yesno']));
|
87 |
$force_jpeg_recompression = trim(esc_sql($_POST['recompress_yesno']));
|
88 |
-
|
89 |
$max_width = trim(esc_sql($_POST['maxwidth']));
|
90 |
$max_height = trim(esc_sql($_POST['maxheight']));
|
91 |
$compression_level = trim(esc_sql($_POST['quality']));
|
92 |
-
|
93 |
$convert_png_to_jpg = trim(esc_sql($_POST['convertpng']));
|
94 |
$convert_gif_to_jpg = trim(esc_sql($_POST['convertgif']));
|
95 |
$convert_bmp_to_jpg = trim(esc_sql($_POST['convertbmp']));
|
96 |
-
|
97 |
-
|
98 |
// If input is not an integer, use previous setting
|
99 |
$max_width = ($max_width == '') ? 0 : $max_width;
|
100 |
$max_width = (ctype_digit(strval($max_width)) == false) ? get_option('jr_resizeupload_width') : $max_width;
|
@@ -104,51 +104,51 @@ function jr_uploadresize_options(){
|
|
104 |
$max_height = ($max_height == '') ? 0 : $max_height;
|
105 |
$max_height = (ctype_digit(strval($max_height)) == false) ? get_option('jr_resizeupload_height') : $max_height;
|
106 |
update_option('jr_resizeupload_height',$max_height);
|
107 |
-
|
108 |
|
109 |
$compression_level = ($compression_level == '') ? 1 : $compression_level;
|
110 |
$compression_level = (ctype_digit(strval($compression_level)) == false) ? get_option('jr_resizeupload_quality') : $compression_level;
|
111 |
-
|
112 |
if($compression_level <= 0) {
|
113 |
-
$compression_level = 1;
|
114 |
}
|
115 |
else if($compression_level >= 100) {
|
116 |
-
$compression_level = 99;
|
117 |
}
|
118 |
-
|
119 |
update_option('jr_resizeupload_quality',$compression_level);
|
120 |
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
if ($resizing_enabled == 'yes') {
|
125 |
-
update_option('jr_resizeupload_resize_yesno','yes'); }
|
126 |
else {
|
127 |
update_option('jr_resizeupload_resize_yesno','no'); }
|
128 |
-
|
129 |
-
|
130 |
if ($force_jpeg_recompression == 'yes') {
|
131 |
update_option('jr_resizeupload_recompress_yesno','yes'); }
|
132 |
else {
|
133 |
update_option('jr_resizeupload_recompress_yesno','no'); }
|
134 |
-
|
135 |
-
|
136 |
if ($convert_png_to_jpg == 'yes') {
|
137 |
update_option('jr_resizeupload_convertpng_yesno','yes'); }
|
138 |
else {
|
139 |
update_option('jr_resizeupload_convertpng_yesno','no'); }
|
140 |
-
|
141 |
if ($convert_gif_to_jpg == 'yes') {
|
142 |
update_option('jr_resizeupload_convertgif_yesno','yes'); }
|
143 |
else {
|
144 |
update_option('jr_resizeupload_convertgif_yesno','no'); }
|
145 |
-
|
146 |
if ($convert_bmp_to_jpg == 'yes') {
|
147 |
update_option('jr_resizeupload_convertbmp_yesno','yes'); }
|
148 |
else {
|
149 |
update_option('jr_resizeupload_convertbmp_yesno','no'); }
|
150 |
-
|
151 |
-
|
152 |
|
153 |
echo('<div id="message" class="updated fade"><p><strong>Options have been updated.</strong></p></div>');
|
154 |
} // if
|
@@ -159,10 +159,10 @@ function jr_uploadresize_options(){
|
|
159 |
$resizing_enabled = get_option('jr_resizeupload_resize_yesno');
|
160 |
$force_jpeg_recompression = get_option('jr_resizeupload_recompress_yesno');
|
161 |
$compression_level = intval(get_option('jr_resizeupload_quality'));
|
162 |
-
|
163 |
$max_width = get_option('jr_resizeupload_width');
|
164 |
$max_height = get_option('jr_resizeupload_height');
|
165 |
-
|
166 |
$convert_png_to_jpg = get_option('jr_resizeupload_convertpng_yesno');
|
167 |
$convert_gif_to_jpg = get_option('jr_resizeupload_convertgif_yesno');
|
168 |
$convert_bmp_to_jpg = get_option('jr_resizeupload_convertbmp_yesno');
|
@@ -201,26 +201,26 @@ function jr_uploadresize_options(){
|
|
201 |
<form method="post" accept-charset="utf-8">
|
202 |
|
203 |
<h2><img src="<?php echo plugins_url('icon-128x128.png', __FILE__ ); ?>" style="float:right; border:1px solid #ddd;margin:0 0 15px 15px;width:100px; height:100px;" />Resize Image After Upload</h2>
|
204 |
-
|
205 |
<div style="max-width:700px">
|
206 |
<p>This plugin automatically resizes uploaded images (JPEG, GIF, and PNG) 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.</p>
|
207 |
-
|
208 |
<p>In addition, the plugin can force re-compression of uploaded JPEG images, regardless of whether they are resized or not; and convert uploaded GIF and PNG images into JPEG format.</p>
|
209 |
-
|
210 |
<p><strong>Note:</strong> the resizing/recompression process will discard the original uploaded file including EXIF data.</p>
|
211 |
-
|
212 |
<p>This plugin is not intended to replace the WordPress <em>add_image_size()</em> function, but rather complement it. Use this plugin to ensure that no excessively large images are stored on your server, then use <em>add_image_size()</em> to create versions of the images suitable for positioning in your website theme.</p>
|
213 |
-
|
214 |
<p>This plugin uses standard PHP 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).</p>
|
215 |
-
|
216 |
<h4 style="font-size: 15px;font-weight: bold;margin: 2em 0 0;">Like the plugin?</h4>
|
217 |
-
|
218 |
<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>
|
219 |
-
|
220 |
<p style="padding-bottom:2em;" class="resizeimage-button-wrapper">
|
221 |
-
|
222 |
<a class="resizeimage-button" href="https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=3W4M254AA3KZG" target="_blank">Donate cash</a>
|
223 |
-
|
224 |
<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>
|
225 |
|
226 |
</p>
|
@@ -234,7 +234,7 @@ function jr_uploadresize_options(){
|
|
234 |
<tr>
|
235 |
<th scope="row">Enable re-sizing</th>
|
236 |
<td valign="top">
|
237 |
-
<select name="yesno" id="yesno">
|
238 |
<option value="no" label="no" <?php echo ($resizing_enabled == 'no') ? 'selected="selected"' : ''; ?>>NO - do not resize images</option>
|
239 |
<option value="yes" label="yes" <?php echo ($resizing_enabled == 'yes') ? 'selected="selected"' : ''; ?>>YES - resize large images</option>
|
240 |
</select>
|
@@ -243,7 +243,7 @@ function jr_uploadresize_options(){
|
|
243 |
|
244 |
<tr>
|
245 |
<th scope="row">Max image dimensions</th>
|
246 |
-
|
247 |
<td>
|
248 |
<fieldset><legend class="screen-reader-text"><span>Maximum width and height</span></legend>
|
249 |
<label for="maxwidth">Max width</label>
|
@@ -255,18 +255,18 @@ function jr_uploadresize_options(){
|
|
255 |
</fieldset>
|
256 |
</td>
|
257 |
|
258 |
-
|
259 |
</tr>
|
260 |
|
261 |
</table>
|
262 |
-
|
263 |
<hr style="margin-top:20px; margin-bottom:30px;">
|
264 |
-
|
265 |
<h3>Compression options</h3>
|
266 |
<p style="max-width:700px">The following settings will only apply to uploaded JPEG images and images converted to JPEG format.</p>
|
267 |
-
|
268 |
<table class="form-table">
|
269 |
-
|
270 |
<tr>
|
271 |
<th scope="row">JPEG compression level</th>
|
272 |
<td valign="top">
|
@@ -280,29 +280,29 @@ function jr_uploadresize_options(){
|
|
280 |
<br>Recommended value: <code>90</code></p>
|
281 |
</td>
|
282 |
</tr>
|
283 |
-
|
284 |
<tr>
|
285 |
<th scope="row">Force JPEG re-compression</th>
|
286 |
<td>
|
287 |
-
<select name="recompress_yesno" id="yesno">
|
288 |
<option value="no" label="no" <?php echo ($force_jpeg_recompression == 'no') ? 'selected="selected"' : ''; ?>>NO - only re-compress resized jpeg images</option>
|
289 |
<option value="yes" label="yes" <?php echo ($force_jpeg_recompression == 'yes') ? 'selected="selected"' : ''; ?>>YES - re-compress all uploaded jpeg images</option>
|
290 |
</select>
|
291 |
</td>
|
292 |
</tr>
|
293 |
-
|
294 |
</table>
|
295 |
-
|
296 |
<?php /* DEFINED HERE FOR FUTURE RELEASE
|
297 |
<hr style="margin-top:20px; margin-bottom:20px;">
|
298 |
-
|
299 |
<h3>Image conversion options</h3>
|
300 |
<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>
|
301 |
-
|
302 |
<p>When enabled, conversion will happen to all uploaded GIF/PNG images, not just ones that require resizing.</p>
|
303 |
-
|
304 |
<table class="form-table">
|
305 |
-
|
306 |
<tr>
|
307 |
<th scope="row">Convert GIF to JPEG</th>
|
308 |
<td>
|
@@ -312,7 +312,7 @@ function jr_uploadresize_options(){
|
|
312 |
</select>
|
313 |
</td>
|
314 |
</tr>
|
315 |
-
|
316 |
<tr>
|
317 |
<th scope="row">Convert PNG to JPEG</th>
|
318 |
<td>
|
@@ -322,15 +322,15 @@ function jr_uploadresize_options(){
|
|
322 |
</select>
|
323 |
</td>
|
324 |
</tr>
|
325 |
-
|
326 |
</table>
|
327 |
*/ ?>
|
328 |
-
|
329 |
<hr style="margin-top:30px;">
|
330 |
|
331 |
<p class="submit" style="margin-top:10px;border-top:1px solid #eee;padding-top:20px;">
|
332 |
<input type="hidden" id="convert-bmp" name="convertbmp" value="no" />
|
333 |
-
<input type="hidden" name="action" value="update" />
|
334 |
<input id="submit" name="jr_options_update" class="button button-primary" type="submit" value="Update Options">
|
335 |
</p>
|
336 |
</form>
|
@@ -344,48 +344,48 @@ function jr_uploadresize_options(){
|
|
344 |
|
345 |
|
346 |
/**
|
347 |
-
* This function will apply changes to the uploaded file
|
348 |
* @param $image_data - contains file, url, type
|
349 |
*/
|
350 |
-
function jr_uploadresize_resize($image_data){
|
351 |
|
352 |
global $DEBUG_LOGGER;
|
353 |
|
354 |
if(
|
355 |
-
$image_data['type'] == 'image/jpeg' ||
|
356 |
-
$image_data['type'] == 'image/jpg' ||
|
357 |
-
$image_data['type'] == 'image/gif' ||
|
358 |
-
$image_data['type'] == 'image/png' ||
|
359 |
$image_data['type'] == 'image/bmp'
|
360 |
-
)
|
361 |
{
|
362 |
|
363 |
// Include the file to carry out the resizing
|
364 |
require_once('class.resize.php');
|
365 |
|
366 |
-
|
367 |
$resizing_enabled = get_option('jr_resizeupload_resize_yesno');
|
368 |
$resizing_enabled = ($resizing_enabled=='yes') ? true : false;
|
369 |
|
370 |
$force_jpeg_recompression = get_option('jr_resizeupload_recompress_yesno');
|
371 |
-
$force_jpeg_recompression = ($force_jpeg_recompression=='yes') ? true : false;
|
372 |
-
|
373 |
$compression_level = get_option('jr_resizeupload_quality');
|
374 |
-
|
375 |
-
|
376 |
-
$max_width = get_option('jr_resizeupload_width')==0
|
377 |
? false : get_option('jr_resizeupload_width');
|
378 |
-
|
379 |
-
$max_height = get_option('jr_resizeupload_height')==0
|
380 |
? false : get_option('jr_resizeupload_height');
|
381 |
|
382 |
-
|
383 |
$convert_png_to_jpg = get_option('jr_resizeupload_convertpng_yesno');
|
384 |
$convert_png_to_jpg = ($convert_png_to_jpg=='yes') ? true : false;
|
385 |
-
|
386 |
$convert_gif_to_jpg = get_option('jr_resizeupload_convertgif_yesno');
|
387 |
$convert_gif_to_jpg = ($convert_gif_to_jpg=='yes') ? true : false;
|
388 |
-
|
389 |
$convert_bmp_to_jpg = get_option('jr_resizeupload_convertbmp_yesno');
|
390 |
$convert_bmp_to_jpg = ($convert_bmp_to_jpg=='yes') ? true : false;
|
391 |
|
@@ -394,77 +394,77 @@ function jr_uploadresize_resize($image_data){
|
|
394 |
$original_info = getimagesize($image_data['file']);
|
395 |
$original_width = $original_info[0];
|
396 |
$original_height = $original_info[1];
|
397 |
-
|
398 |
$original_is_jpg = false;
|
399 |
$original_is_png = false;
|
400 |
$original_is_gif = false;
|
401 |
$original_is_bmp = false;
|
402 |
-
|
403 |
switch($image_data['type']) {
|
404 |
-
|
405 |
case 'image/jpg' :
|
406 |
case 'image/jpeg' : $original_is_jpg = true; break;
|
407 |
-
|
408 |
case 'image/png' : $original_is_png = true; break;
|
409 |
-
|
410 |
case 'image/gif' : $original_is_gif = true; break;
|
411 |
-
|
412 |
case 'image/bmp' : $original_is_bmp = true; break;
|
413 |
-
|
414 |
}
|
415 |
-
|
416 |
|
417 |
-
|
|
|
418 |
|
419 |
|
420 |
-
//
|
421 |
// Perform resizing operations if reduction is required
|
422 |
if(
|
423 |
-
$resizing_enabled
|
424 |
&& ($max_width || $max_height) // resize in at least one dimension
|
425 |
&& (
|
426 |
($max_width && ($original_width > $max_width)) // width possibly needs resizing
|
427 |
-
||
|
428 |
($max_height && ($original_height > $max_height)) // height possibly needs resizing
|
429 |
)
|
430 |
&& !$original_is_bmp) // plugin does not work with bitmaps
|
431 |
{
|
432 |
|
433 |
if($DEBUG_LOGGER) error_log('LOG: '.print_r('--resizing', true));
|
434 |
-
|
435 |
$protect_image = true;
|
436 |
$resize_direction = null;
|
437 |
$resize_max = null;
|
438 |
|
439 |
|
440 |
// Width is unlimited, limit by height
|
441 |
-
if((!$max_width && $max_height)
|
442 |
-
&& ($original_height > $max_height)) {
|
443 |
-
|
444 |
$resize_direction = 'H';
|
445 |
$resize_max = $max_height;
|
446 |
if($DEBUG_LOGGER) error_log('LOG: '.print_r(' >--by-height (width-unlimited)', true));
|
447 |
}
|
448 |
-
|
449 |
// Height is unlimited, limit by width
|
450 |
-
else if((!$max_height && $max_width)
|
451 |
&& ($original_width > $max_width)) {
|
452 |
-
|
453 |
$resize_direction = 'W';
|
454 |
$resize_max = $max_width;
|
455 |
-
|
456 |
if($DEBUG_LOGGER) error_log('LOG: '.print_r(' >--by-width (height-unlimited)', true));
|
457 |
}
|
458 |
-
|
459 |
// Both dimensions require limiting, figure out which
|
460 |
else {
|
461 |
-
|
462 |
if(($original_height/$max_height) > ($original_width/$max_width)) {
|
463 |
$resize_direction = 'H';
|
464 |
$resize_max = $max_height;
|
465 |
if($DEBUG_LOGGER) error_log('LOG: '.print_r(' >--by-height', true));
|
466 |
}
|
467 |
-
|
468 |
else {
|
469 |
$resize_direction = 'W';
|
470 |
$resize_max = $max_width;
|
@@ -473,34 +473,34 @@ if($DEBUG_LOGGER) error_log('LOG: '.print_r('upload-start', true));
|
|
473 |
}
|
474 |
|
475 |
if(!is_null($resize_direction) && !is_null($resize_max)) {
|
476 |
-
|
477 |
$objResize = new RVJ_ImageResize(
|
478 |
-
$image_data['file'], $image_data['file'],
|
479 |
-
$resize_direction, $resize_max,
|
480 |
$protect_image, $compression_level
|
481 |
);
|
482 |
-
|
483 |
-
|
484 |
if($DEBUG_LOGGER) error_log('LOG: '.print_r(' >--resize-done', true));
|
485 |
}
|
486 |
-
}
|
487 |
-
|
488 |
-
|
489 |
//
|
490 |
// Resizing is not required, but still need to re-compress to desired quality and filetype
|
491 |
else if(($original_is_jpg && $force_jpeg_recompression)
|
492 |
|| ($original_is_png && $convert_png_to_jpg)
|
493 |
-
|| ($original_is_gif && $convert_gif_to_jpg)
|
494 |
|| ($original_is_bmp && $convert_bmp_to_jpg)) {
|
495 |
-
|
496 |
$protect_image = false;
|
497 |
-
|
498 |
$objResize = new RVJ_ImageResize($image_data['file'], $image_data['file'], 'P', 100, $protect_image, $compression_level);
|
499 |
-
|
500 |
if($DEBUG_LOGGER) error_log('LOG: '.print_r('--recompression/conversion', true));
|
501 |
}
|
502 |
-
|
503 |
-
|
504 |
//
|
505 |
// No resizing, recompression, or conversion required
|
506 |
else {
|
@@ -508,8 +508,8 @@ if($DEBUG_LOGGER) error_log('LOG: '.print_r('upload-start', true));
|
|
508 |
}
|
509 |
|
510 |
if($DEBUG_LOGGER) error_log('LOG: '.print_r("end\n", true));
|
511 |
-
|
512 |
-
} // if(...)
|
513 |
-
|
514 |
return $image_data;
|
515 |
-
} // function jr_uploadresize_resize($image_data){
|
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: iamphilrae
|
7 |
+
Version: 1.6.2
|
8 |
Author URI: http://www.philr.ae/
|
9 |
|
10 |
+
Copyright (C) 2015 iamphilrae
|
11 |
+
|
12 |
|
13 |
Includes hints and code by:
|
14 |
Huiz.net (www.huiz.net)
|
15 |
Jacob Wyke (www.redvodkajelly.com)
|
16 |
+
Paolo Tresso / Pixline (http://pixline.net)
|
17 |
|
18 |
This program is free software; you can redistribute it and/or
|
19 |
modify it under the terms of the GNU General Public License
|
30 |
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
31 |
*/
|
32 |
|
33 |
+
$PLUGIN_VERSION = '1.6.2';
|
34 |
$DEBUG_LOGGER = false;
|
35 |
|
36 |
|
51 |
|
52 |
|
53 |
// Hook in the options page
|
54 |
+
add_action('admin_menu', 'jr_uploadresize_options_page');
|
55 |
|
56 |
// Hook the function to the upload handler
|
57 |
add_action('wp_handle_upload', 'jr_uploadresize_resize');
|
58 |
|
59 |
|
60 |
|
61 |
+
|
62 |
/**
|
63 |
* Add the options page
|
64 |
*/
|
65 |
function jr_uploadresize_options_page(){
|
66 |
if(function_exists('add_options_page')){
|
67 |
add_options_page(
|
68 |
+
'Resize Image After Upload',
|
69 |
+
'Resize Image Upload',
|
70 |
+
'manage_options',
|
71 |
+
'resize-after-upload',
|
72 |
'jr_uploadresize_options'
|
73 |
);
|
74 |
+
}
|
75 |
+
} // function jr_uploadresize_options_page(){
|
76 |
|
77 |
|
78 |
|
79 |
+
/**
|
80 |
* Define the Options page for the plugin
|
81 |
*/
|
82 |
function jr_uploadresize_options(){
|
83 |
|
84 |
if(isset($_POST['jr_options_update'])) {
|
85 |
+
|
86 |
$resizing_enabled = trim(esc_sql($_POST['yesno']));
|
87 |
$force_jpeg_recompression = trim(esc_sql($_POST['recompress_yesno']));
|
88 |
+
|
89 |
$max_width = trim(esc_sql($_POST['maxwidth']));
|
90 |
$max_height = trim(esc_sql($_POST['maxheight']));
|
91 |
$compression_level = trim(esc_sql($_POST['quality']));
|
92 |
+
|
93 |
$convert_png_to_jpg = trim(esc_sql($_POST['convertpng']));
|
94 |
$convert_gif_to_jpg = trim(esc_sql($_POST['convertgif']));
|
95 |
$convert_bmp_to_jpg = trim(esc_sql($_POST['convertbmp']));
|
96 |
+
|
97 |
+
|
98 |
// If input is not an integer, use previous setting
|
99 |
$max_width = ($max_width == '') ? 0 : $max_width;
|
100 |
$max_width = (ctype_digit(strval($max_width)) == false) ? get_option('jr_resizeupload_width') : $max_width;
|
104 |
$max_height = ($max_height == '') ? 0 : $max_height;
|
105 |
$max_height = (ctype_digit(strval($max_height)) == false) ? get_option('jr_resizeupload_height') : $max_height;
|
106 |
update_option('jr_resizeupload_height',$max_height);
|
107 |
+
|
108 |
|
109 |
$compression_level = ($compression_level == '') ? 1 : $compression_level;
|
110 |
$compression_level = (ctype_digit(strval($compression_level)) == false) ? get_option('jr_resizeupload_quality') : $compression_level;
|
111 |
+
|
112 |
if($compression_level <= 0) {
|
113 |
+
$compression_level = 1;
|
114 |
}
|
115 |
else if($compression_level >= 100) {
|
116 |
+
$compression_level = 99;
|
117 |
}
|
118 |
+
|
119 |
update_option('jr_resizeupload_quality',$compression_level);
|
120 |
|
121 |
+
|
122 |
+
|
123 |
+
|
124 |
if ($resizing_enabled == 'yes') {
|
125 |
+
update_option('jr_resizeupload_resize_yesno','yes'); }
|
126 |
else {
|
127 |
update_option('jr_resizeupload_resize_yesno','no'); }
|
128 |
+
|
129 |
+
|
130 |
if ($force_jpeg_recompression == 'yes') {
|
131 |
update_option('jr_resizeupload_recompress_yesno','yes'); }
|
132 |
else {
|
133 |
update_option('jr_resizeupload_recompress_yesno','no'); }
|
134 |
+
|
135 |
+
|
136 |
if ($convert_png_to_jpg == 'yes') {
|
137 |
update_option('jr_resizeupload_convertpng_yesno','yes'); }
|
138 |
else {
|
139 |
update_option('jr_resizeupload_convertpng_yesno','no'); }
|
140 |
+
|
141 |
if ($convert_gif_to_jpg == 'yes') {
|
142 |
update_option('jr_resizeupload_convertgif_yesno','yes'); }
|
143 |
else {
|
144 |
update_option('jr_resizeupload_convertgif_yesno','no'); }
|
145 |
+
|
146 |
if ($convert_bmp_to_jpg == 'yes') {
|
147 |
update_option('jr_resizeupload_convertbmp_yesno','yes'); }
|
148 |
else {
|
149 |
update_option('jr_resizeupload_convertbmp_yesno','no'); }
|
150 |
+
|
151 |
+
|
152 |
|
153 |
echo('<div id="message" class="updated fade"><p><strong>Options have been updated.</strong></p></div>');
|
154 |
} // if
|
159 |
$resizing_enabled = get_option('jr_resizeupload_resize_yesno');
|
160 |
$force_jpeg_recompression = get_option('jr_resizeupload_recompress_yesno');
|
161 |
$compression_level = intval(get_option('jr_resizeupload_quality'));
|
162 |
+
|
163 |
$max_width = get_option('jr_resizeupload_width');
|
164 |
$max_height = get_option('jr_resizeupload_height');
|
165 |
+
|
166 |
$convert_png_to_jpg = get_option('jr_resizeupload_convertpng_yesno');
|
167 |
$convert_gif_to_jpg = get_option('jr_resizeupload_convertgif_yesno');
|
168 |
$convert_bmp_to_jpg = get_option('jr_resizeupload_convertbmp_yesno');
|
201 |
<form method="post" accept-charset="utf-8">
|
202 |
|
203 |
<h2><img src="<?php echo plugins_url('icon-128x128.png', __FILE__ ); ?>" style="float:right; border:1px solid #ddd;margin:0 0 15px 15px;width:100px; height:100px;" />Resize Image After Upload</h2>
|
204 |
+
|
205 |
<div style="max-width:700px">
|
206 |
<p>This plugin automatically resizes uploaded images (JPEG, GIF, and PNG) 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.</p>
|
207 |
+
|
208 |
<p>In addition, the plugin can force re-compression of uploaded JPEG images, regardless of whether they are resized or not; and convert uploaded GIF and PNG images into JPEG format.</p>
|
209 |
+
|
210 |
<p><strong>Note:</strong> the resizing/recompression process will discard the original uploaded file including EXIF data.</p>
|
211 |
+
|
212 |
<p>This plugin is not intended to replace the WordPress <em>add_image_size()</em> function, but rather complement it. Use this plugin to ensure that no excessively large images are stored on your server, then use <em>add_image_size()</em> to create versions of the images suitable for positioning in your website theme.</p>
|
213 |
+
|
214 |
<p>This plugin uses standard PHP 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).</p>
|
215 |
+
|
216 |
<h4 style="font-size: 15px;font-weight: bold;margin: 2em 0 0;">Like the plugin?</h4>
|
217 |
+
|
218 |
<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>
|
219 |
+
|
220 |
<p style="padding-bottom:2em;" class="resizeimage-button-wrapper">
|
221 |
+
|
222 |
<a class="resizeimage-button" href="https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=3W4M254AA3KZG" target="_blank">Donate cash</a>
|
223 |
+
|
224 |
<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>
|
225 |
|
226 |
</p>
|
234 |
<tr>
|
235 |
<th scope="row">Enable re-sizing</th>
|
236 |
<td valign="top">
|
237 |
+
<select name="yesno" id="yesno">
|
238 |
<option value="no" label="no" <?php echo ($resizing_enabled == 'no') ? 'selected="selected"' : ''; ?>>NO - do not resize images</option>
|
239 |
<option value="yes" label="yes" <?php echo ($resizing_enabled == 'yes') ? 'selected="selected"' : ''; ?>>YES - resize large images</option>
|
240 |
</select>
|
243 |
|
244 |
<tr>
|
245 |
<th scope="row">Max image dimensions</th>
|
246 |
+
|
247 |
<td>
|
248 |
<fieldset><legend class="screen-reader-text"><span>Maximum width and height</span></legend>
|
249 |
<label for="maxwidth">Max width</label>
|
255 |
</fieldset>
|
256 |
</td>
|
257 |
|
258 |
+
|
259 |
</tr>
|
260 |
|
261 |
</table>
|
262 |
+
|
263 |
<hr style="margin-top:20px; margin-bottom:30px;">
|
264 |
+
|
265 |
<h3>Compression options</h3>
|
266 |
<p style="max-width:700px">The following settings will only apply to uploaded JPEG images and images converted to JPEG format.</p>
|
267 |
+
|
268 |
<table class="form-table">
|
269 |
+
|
270 |
<tr>
|
271 |
<th scope="row">JPEG compression level</th>
|
272 |
<td valign="top">
|
280 |
<br>Recommended value: <code>90</code></p>
|
281 |
</td>
|
282 |
</tr>
|
283 |
+
|
284 |
<tr>
|
285 |
<th scope="row">Force JPEG re-compression</th>
|
286 |
<td>
|
287 |
+
<select name="recompress_yesno" id="yesno">
|
288 |
<option value="no" label="no" <?php echo ($force_jpeg_recompression == 'no') ? 'selected="selected"' : ''; ?>>NO - only re-compress resized jpeg images</option>
|
289 |
<option value="yes" label="yes" <?php echo ($force_jpeg_recompression == 'yes') ? 'selected="selected"' : ''; ?>>YES - re-compress all uploaded jpeg images</option>
|
290 |
</select>
|
291 |
</td>
|
292 |
</tr>
|
293 |
+
|
294 |
</table>
|
295 |
+
|
296 |
<?php /* DEFINED HERE FOR FUTURE RELEASE
|
297 |
<hr style="margin-top:20px; margin-bottom:20px;">
|
298 |
+
|
299 |
<h3>Image conversion options</h3>
|
300 |
<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>
|
301 |
+
|
302 |
<p>When enabled, conversion will happen to all uploaded GIF/PNG images, not just ones that require resizing.</p>
|
303 |
+
|
304 |
<table class="form-table">
|
305 |
+
|
306 |
<tr>
|
307 |
<th scope="row">Convert GIF to JPEG</th>
|
308 |
<td>
|
312 |
</select>
|
313 |
</td>
|
314 |
</tr>
|
315 |
+
|
316 |
<tr>
|
317 |
<th scope="row">Convert PNG to JPEG</th>
|
318 |
<td>
|
322 |
</select>
|
323 |
</td>
|
324 |
</tr>
|
325 |
+
|
326 |
</table>
|
327 |
*/ ?>
|
328 |
+
|
329 |
<hr style="margin-top:30px;">
|
330 |
|
331 |
<p class="submit" style="margin-top:10px;border-top:1px solid #eee;padding-top:20px;">
|
332 |
<input type="hidden" id="convert-bmp" name="convertbmp" value="no" />
|
333 |
+
<input type="hidden" name="action" value="update" />
|
334 |
<input id="submit" name="jr_options_update" class="button button-primary" type="submit" value="Update Options">
|
335 |
</p>
|
336 |
</form>
|
344 |
|
345 |
|
346 |
/**
|
347 |
+
* This function will apply changes to the uploaded file
|
348 |
* @param $image_data - contains file, url, type
|
349 |
*/
|
350 |
+
function jr_uploadresize_resize($image_data){
|
351 |
|
352 |
global $DEBUG_LOGGER;
|
353 |
|
354 |
if(
|
355 |
+
$image_data['type'] == 'image/jpeg' ||
|
356 |
+
$image_data['type'] == 'image/jpg' ||
|
357 |
+
$image_data['type'] == 'image/gif' ||
|
358 |
+
$image_data['type'] == 'image/png' ||
|
359 |
$image_data['type'] == 'image/bmp'
|
360 |
+
)
|
361 |
{
|
362 |
|
363 |
// Include the file to carry out the resizing
|
364 |
require_once('class.resize.php');
|
365 |
|
366 |
+
|
367 |
$resizing_enabled = get_option('jr_resizeupload_resize_yesno');
|
368 |
$resizing_enabled = ($resizing_enabled=='yes') ? true : false;
|
369 |
|
370 |
$force_jpeg_recompression = get_option('jr_resizeupload_recompress_yesno');
|
371 |
+
$force_jpeg_recompression = ($force_jpeg_recompression=='yes') ? true : false;
|
372 |
+
|
373 |
$compression_level = get_option('jr_resizeupload_quality');
|
374 |
+
|
375 |
+
|
376 |
+
$max_width = get_option('jr_resizeupload_width')==0
|
377 |
? false : get_option('jr_resizeupload_width');
|
378 |
+
|
379 |
+
$max_height = get_option('jr_resizeupload_height')==0
|
380 |
? false : get_option('jr_resizeupload_height');
|
381 |
|
382 |
+
|
383 |
$convert_png_to_jpg = get_option('jr_resizeupload_convertpng_yesno');
|
384 |
$convert_png_to_jpg = ($convert_png_to_jpg=='yes') ? true : false;
|
385 |
+
|
386 |
$convert_gif_to_jpg = get_option('jr_resizeupload_convertgif_yesno');
|
387 |
$convert_gif_to_jpg = ($convert_gif_to_jpg=='yes') ? true : false;
|
388 |
+
|
389 |
$convert_bmp_to_jpg = get_option('jr_resizeupload_convertbmp_yesno');
|
390 |
$convert_bmp_to_jpg = ($convert_bmp_to_jpg=='yes') ? true : false;
|
391 |
|
394 |
$original_info = getimagesize($image_data['file']);
|
395 |
$original_width = $original_info[0];
|
396 |
$original_height = $original_info[1];
|
397 |
+
|
398 |
$original_is_jpg = false;
|
399 |
$original_is_png = false;
|
400 |
$original_is_gif = false;
|
401 |
$original_is_bmp = false;
|
402 |
+
|
403 |
switch($image_data['type']) {
|
404 |
+
|
405 |
case 'image/jpg' :
|
406 |
case 'image/jpeg' : $original_is_jpg = true; break;
|
407 |
+
|
408 |
case 'image/png' : $original_is_png = true; break;
|
409 |
+
|
410 |
case 'image/gif' : $original_is_gif = true; break;
|
411 |
+
|
412 |
case 'image/bmp' : $original_is_bmp = true; break;
|
413 |
+
|
414 |
}
|
|
|
415 |
|
416 |
+
|
417 |
+
if($DEBUG_LOGGER) error_log('LOG: '.print_r('upload-start', true));
|
418 |
|
419 |
|
420 |
+
//
|
421 |
// Perform resizing operations if reduction is required
|
422 |
if(
|
423 |
+
$resizing_enabled
|
424 |
&& ($max_width || $max_height) // resize in at least one dimension
|
425 |
&& (
|
426 |
($max_width && ($original_width > $max_width)) // width possibly needs resizing
|
427 |
+
||
|
428 |
($max_height && ($original_height > $max_height)) // height possibly needs resizing
|
429 |
)
|
430 |
&& !$original_is_bmp) // plugin does not work with bitmaps
|
431 |
{
|
432 |
|
433 |
if($DEBUG_LOGGER) error_log('LOG: '.print_r('--resizing', true));
|
434 |
+
|
435 |
$protect_image = true;
|
436 |
$resize_direction = null;
|
437 |
$resize_max = null;
|
438 |
|
439 |
|
440 |
// Width is unlimited, limit by height
|
441 |
+
if((!$max_width && $max_height)
|
442 |
+
&& ($original_height > $max_height)) {
|
443 |
+
|
444 |
$resize_direction = 'H';
|
445 |
$resize_max = $max_height;
|
446 |
if($DEBUG_LOGGER) error_log('LOG: '.print_r(' >--by-height (width-unlimited)', true));
|
447 |
}
|
448 |
+
|
449 |
// Height is unlimited, limit by width
|
450 |
+
else if((!$max_height && $max_width)
|
451 |
&& ($original_width > $max_width)) {
|
452 |
+
|
453 |
$resize_direction = 'W';
|
454 |
$resize_max = $max_width;
|
455 |
+
|
456 |
if($DEBUG_LOGGER) error_log('LOG: '.print_r(' >--by-width (height-unlimited)', true));
|
457 |
}
|
458 |
+
|
459 |
// Both dimensions require limiting, figure out which
|
460 |
else {
|
461 |
+
|
462 |
if(($original_height/$max_height) > ($original_width/$max_width)) {
|
463 |
$resize_direction = 'H';
|
464 |
$resize_max = $max_height;
|
465 |
if($DEBUG_LOGGER) error_log('LOG: '.print_r(' >--by-height', true));
|
466 |
}
|
467 |
+
|
468 |
else {
|
469 |
$resize_direction = 'W';
|
470 |
$resize_max = $max_width;
|
473 |
}
|
474 |
|
475 |
if(!is_null($resize_direction) && !is_null($resize_max)) {
|
476 |
+
|
477 |
$objResize = new RVJ_ImageResize(
|
478 |
+
$image_data['file'], $image_data['file'],
|
479 |
+
$resize_direction, $resize_max,
|
480 |
$protect_image, $compression_level
|
481 |
);
|
482 |
+
|
483 |
+
|
484 |
if($DEBUG_LOGGER) error_log('LOG: '.print_r(' >--resize-done', true));
|
485 |
}
|
486 |
+
}
|
487 |
+
|
488 |
+
|
489 |
//
|
490 |
// Resizing is not required, but still need to re-compress to desired quality and filetype
|
491 |
else if(($original_is_jpg && $force_jpeg_recompression)
|
492 |
|| ($original_is_png && $convert_png_to_jpg)
|
493 |
+
|| ($original_is_gif && $convert_gif_to_jpg)
|
494 |
|| ($original_is_bmp && $convert_bmp_to_jpg)) {
|
495 |
+
|
496 |
$protect_image = false;
|
497 |
+
|
498 |
$objResize = new RVJ_ImageResize($image_data['file'], $image_data['file'], 'P', 100, $protect_image, $compression_level);
|
499 |
+
|
500 |
if($DEBUG_LOGGER) error_log('LOG: '.print_r('--recompression/conversion', true));
|
501 |
}
|
502 |
+
|
503 |
+
|
504 |
//
|
505 |
// No resizing, recompression, or conversion required
|
506 |
else {
|
508 |
}
|
509 |
|
510 |
if($DEBUG_LOGGER) error_log('LOG: '.print_r("end\n", true));
|
511 |
+
|
512 |
+
} // if(...)
|
513 |
+
|
514 |
return $image_data;
|
515 |
+
} // function jr_uploadresize_resize($image_data){
|