Version Description
Download this release
Release Info
Developer | jepsonrae |
Plugin | Resize Image After Upload |
Version | 1.0.0 |
Comparing to | |
See all releases |
Version 1.0.0
- class.resize.php +371 -0
- readme.txt +50 -0
- resize-image-after-upload.php +150 -0
- screenshot-1.png +0 -0
class.resize.php
ADDED
@@ -0,0 +1,371 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/*
|
3 |
+
* PHP Image Resize Class
|
4 |
+
*
|
5 |
+
* Class to deal with resizing images using PHP.
|
6 |
+
* Will resize any JPG, GIF or PNG file.
|
7 |
+
*
|
8 |
+
* Written By Jacob Wyke - jacob@redvodkajelly.com - www.redvodkajelly.com
|
9 |
+
* Edited by A. Huizinga 2009, 22 Jan: changed used of function imagecopyresized into imagecopyresampled
|
10 |
+
*
|
11 |
+
* LICENSE
|
12 |
+
* Feel free to use this as you wish, just give me credit where credits due and drop me an email telling me what your using it for so I can check out all the cool ways its been used.
|
13 |
+
*
|
14 |
+
* USAGE
|
15 |
+
* To use this class simply call it with the following details:
|
16 |
+
*
|
17 |
+
* Path to original image,
|
18 |
+
* Path to save new image,
|
19 |
+
* Resize type,
|
20 |
+
* Resize Data
|
21 |
+
*
|
22 |
+
* The resize type can be one of four:
|
23 |
+
*
|
24 |
+
* W = Width
|
25 |
+
* H = Height
|
26 |
+
* P = Percentage
|
27 |
+
* C = Custom
|
28 |
+
*
|
29 |
+
* All of these take integers except Custom that takes an array of two integers - for width and height.
|
30 |
+
*
|
31 |
+
* $objResize = new RVJ_ImageResize("myImage.png", "myThumb.png", "W", "400");
|
32 |
+
* $objResize = new RVJ_ImageResize("myImage.jpg", "myThumb.jpg", "H", "150");
|
33 |
+
* $objResize = new RVJ_ImageResize("myImage.gif", "myThumb.gif", "P", "50");
|
34 |
+
* $objResize = new RVJ_ImageResize("myImage.png", "myThumb.png", "C", array("400", "300"));
|
35 |
+
*
|
36 |
+
* When resizing by width, height and percentage, the image will keep its original ratio. Custom will simply resizes the image to whatever values you want - without keeping the original ratio.
|
37 |
+
*
|
38 |
+
* The class can handle jpg, png and gif images.
|
39 |
+
*
|
40 |
+
* The class will always save the image that it resizes, however you can also have it display the image:
|
41 |
+
*
|
42 |
+
* $objResize->showImage($resize->im2);
|
43 |
+
*
|
44 |
+
* The class holds the original image in the variable "im" and the new image in "im2". Therefore the code above will show the newly created image.
|
45 |
+
*
|
46 |
+
* You can get information about the image by doing the following:
|
47 |
+
*
|
48 |
+
* print_r($objResize->findResourceDetails($objResize->resOriginalImage));
|
49 |
+
* print_r($objResize->findResourceDetails($objResize->resResizedImage));
|
50 |
+
*
|
51 |
+
* This will be useful if you wish to retrieve any details about the images.
|
52 |
+
*
|
53 |
+
* By default the class will stop you from enlarging your images (or else they will look grainy) and if you want to do this you must turn off the protection mode by passing a 5th parameter
|
54 |
+
*
|
55 |
+
* $objResize = new RVJ_ImageResize("myImage.gif", "myEnlargedImage.gif", "P", "200", false);
|
56 |
+
*
|
57 |
+
*/
|
58 |
+
|
59 |
+
class RVJ_ImageResize {
|
60 |
+
|
61 |
+
var $strOriginalImagePath;
|
62 |
+
var $strResizedImagePath;
|
63 |
+
var $arrOriginalDetails;
|
64 |
+
var $arrResizedDetails;
|
65 |
+
var $resOriginalImage;
|
66 |
+
var $resResizedImage;
|
67 |
+
var $boolProtect = true;
|
68 |
+
|
69 |
+
/*
|
70 |
+
*
|
71 |
+
* @Method: __constructor
|
72 |
+
* @Parameters: 5
|
73 |
+
* @Param-1: strPath - String - The path to the image
|
74 |
+
* @Param-2: strSavePath - String - The path to save the new image to
|
75 |
+
* @Param-3: strType - String - The type of resize you want to perform
|
76 |
+
* @Param-4: value - Number/Array - The resize dimensions
|
77 |
+
* @Param-5: boolProect - Boolen - Protects the image so that it doesnt resize an image if its already smaller
|
78 |
+
* @Description: Calls the RVJ_Pagination method so its php 4 compatible
|
79 |
+
*
|
80 |
+
*/
|
81 |
+
|
82 |
+
function __constructor($strPath, $strSavePath, $strType = "W", $value = "150", $boolProtect = true){
|
83 |
+
$this->RVJ_ImageResize($strPath, $strSavePath, $strType, $value);
|
84 |
+
}
|
85 |
+
|
86 |
+
/*
|
87 |
+
*
|
88 |
+
* @Method: RVJ_ImageResize
|
89 |
+
* @Parameters: 5
|
90 |
+
* @Param-1: strPath - String - The path to the image
|
91 |
+
* @Param-2: strSavePath - String - The path to save the new image to
|
92 |
+
* @Param-3: strType - String - The type of resize you want to perform
|
93 |
+
* @Param-4: value - Number/Array - The resize dimensions
|
94 |
+
* @Param-5: boolProect - Boolen - Protects the image so that it doesnt resize an image if its already smaller
|
95 |
+
* @Description: Calls the RVJ_Pagination method so its php 4 compatible
|
96 |
+
*
|
97 |
+
*/
|
98 |
+
|
99 |
+
function RVJ_ImageResize($strPath, $strSavePath, $strType = "W", $value = "150", $boolProtect = true){
|
100 |
+
//save the image/path details
|
101 |
+
$this->strOriginalImagePath = $strPath;
|
102 |
+
$this->strResizedImagePath = $strSavePath;
|
103 |
+
$this->boolProtect = $boolProtect;
|
104 |
+
|
105 |
+
//get the image dimensions
|
106 |
+
$this->arrOriginalDetails = getimagesize($this->strOriginalImagePath);
|
107 |
+
$this->arrResizedDetails = $this->arrOriginalDetails;
|
108 |
+
|
109 |
+
//create an image resouce to work with
|
110 |
+
$this->resOriginalImage = $this->createImage($this->strOriginalImagePath);
|
111 |
+
|
112 |
+
//select the image resize type
|
113 |
+
switch(strtoupper($strType)){
|
114 |
+
case "P":
|
115 |
+
$this->resizeToPercent($value);
|
116 |
+
break;
|
117 |
+
case "H":
|
118 |
+
$this->resizeToHeight($value);
|
119 |
+
break;
|
120 |
+
case "C":
|
121 |
+
$this->resizeToCustom($value);
|
122 |
+
break;
|
123 |
+
case "W":
|
124 |
+
default:
|
125 |
+
$this->resizeToWidth($value);
|
126 |
+
break;
|
127 |
+
}
|
128 |
+
}
|
129 |
+
|
130 |
+
/*
|
131 |
+
*
|
132 |
+
* @Method: findResourceDetails
|
133 |
+
* @Parameters: 1
|
134 |
+
* @Param-1: resImage - Resource - The image resource you want details on
|
135 |
+
* @Description: Returns an array of details about the resource identifier that you pass it
|
136 |
+
*
|
137 |
+
*/
|
138 |
+
|
139 |
+
function findResourceDetails($resImage){
|
140 |
+
//check to see what image is being requested
|
141 |
+
if($resImage==$this->resResizedImage){
|
142 |
+
//return new image details
|
143 |
+
return $this->arrResizedDetails;
|
144 |
+
}else{
|
145 |
+
//return original image details
|
146 |
+
return $this->arrOriginalDetails;
|
147 |
+
}
|
148 |
+
}
|
149 |
+
|
150 |
+
/*
|
151 |
+
*
|
152 |
+
* @Method: updateNewDetails
|
153 |
+
* @Parameters: 0
|
154 |
+
* @Description: Updates the width and height values of the resized details array
|
155 |
+
*
|
156 |
+
*/
|
157 |
+
|
158 |
+
function updateNewDetails(){
|
159 |
+
$this->arrResizedDetails[0] = imagesx($this->resResizedImage);
|
160 |
+
$this->arrResizedDetails[1] = imagesy($this->resResizedImage);
|
161 |
+
}
|
162 |
+
|
163 |
+
/*
|
164 |
+
*
|
165 |
+
* @Method: createImage
|
166 |
+
* @Parameters: 1
|
167 |
+
* @Param-1: strImagePath - String - The path to the image
|
168 |
+
* @Description: Created an image resource of the image path passed to it
|
169 |
+
*
|
170 |
+
*/
|
171 |
+
|
172 |
+
function createImage($strImagePath){
|
173 |
+
//get the image details
|
174 |
+
$arrDetails = $this->findResourceDetails($strImagePath);
|
175 |
+
|
176 |
+
//choose the correct function for the image type
|
177 |
+
switch($arrDetails['mime']){
|
178 |
+
case "image/jpeg":
|
179 |
+
return imagecreatefromjpeg($strImagePath);
|
180 |
+
break;
|
181 |
+
case "image/png":
|
182 |
+
return imagecreatefrompng($strImagePath);
|
183 |
+
break;
|
184 |
+
case "image/gif":
|
185 |
+
return imagecreatefromgif($strImagePath);
|
186 |
+
break;
|
187 |
+
}
|
188 |
+
}
|
189 |
+
|
190 |
+
/*
|
191 |
+
*
|
192 |
+
* @Method: saveImage
|
193 |
+
* @Parameters: 1
|
194 |
+
* @Param-1: numQuality - Number - The quality to save the image at
|
195 |
+
* @Description: Saves the resize image
|
196 |
+
*
|
197 |
+
*/
|
198 |
+
|
199 |
+
function saveImage($numQuality = 95){
|
200 |
+
switch($this->arrResizedDetails['mime']){
|
201 |
+
case "image/jpeg":
|
202 |
+
imagejpeg($this->resResizedImage, $this->strResizedImagePath, $numQuality);
|
203 |
+
break;
|
204 |
+
case "image/png":
|
205 |
+
// imagepng = [0-9] (not [0-100])
|
206 |
+
imagepng($this->resResizedImage, $this->strResizedImagePath, 7);
|
207 |
+
break;
|
208 |
+
case "image/gif":
|
209 |
+
imagegif($this->resResizedImage, $this->strResizedImagePath, $numQuality);
|
210 |
+
break;
|
211 |
+
}
|
212 |
+
}
|
213 |
+
|
214 |
+
/*
|
215 |
+
*
|
216 |
+
* @Method: showImage
|
217 |
+
* @Parameters: 1
|
218 |
+
* @Param-1: resImage - Resource - The resource of the image you want to display
|
219 |
+
* @Description: Displays the image resouce on the screen
|
220 |
+
*
|
221 |
+
*/
|
222 |
+
|
223 |
+
function showImage($resImage){
|
224 |
+
//get the image details
|
225 |
+
$arrDetails = $this->findResourceDetails($resImage);
|
226 |
+
|
227 |
+
//set the correct header for the image we are displaying
|
228 |
+
header("Content-type: ".$arrDetails['mime']);
|
229 |
+
switch($arrDetails['mime']){
|
230 |
+
case "image/jpeg":
|
231 |
+
return imagejpeg($resImage);
|
232 |
+
break;
|
233 |
+
case "image/png":
|
234 |
+
return imagepng($resImage);
|
235 |
+
break;
|
236 |
+
case "image/gif":
|
237 |
+
return imagegif($resImage);
|
238 |
+
break;
|
239 |
+
}
|
240 |
+
}
|
241 |
+
|
242 |
+
/*
|
243 |
+
*
|
244 |
+
* @Method: destroyImage
|
245 |
+
* @Parameters: 1
|
246 |
+
* @Param-1: resImage - Resource - The image resource you want to destroy
|
247 |
+
* @Description: Destroys the image resource and so cleans things up
|
248 |
+
*
|
249 |
+
*/
|
250 |
+
|
251 |
+
function destroyImage($resImage){
|
252 |
+
imagedestroy($resImage);
|
253 |
+
}
|
254 |
+
|
255 |
+
/*
|
256 |
+
*
|
257 |
+
* @Method: _resize
|
258 |
+
* @Parameters: 2
|
259 |
+
* @Param-1: numWidth - Number - The width of the image in pixels
|
260 |
+
* @Param-2: numHeight - Number - The height of the image in pixes
|
261 |
+
* @Description: Resizes the image by creatin a new canvas and copying the image over onto it. DONT CALL THIS METHOD DIRECTLY - USE THE METHODS BELOW
|
262 |
+
*
|
263 |
+
*/
|
264 |
+
|
265 |
+
function _resize($numWidth, $numHeight){
|
266 |
+
//check for image protection
|
267 |
+
if($this->_imageProtect($numWidth, $numHeight)){
|
268 |
+
if($this->arrOriginalDetails['mime']=="image/gif"){
|
269 |
+
//GIF image
|
270 |
+
$this->resResizedImage = imagecreate($numWidth, $numHeight);
|
271 |
+
}else if($this->arrOriginalDetails['mime']=="image/jpeg"){
|
272 |
+
//JPG image
|
273 |
+
$this->resResizedImage = imagecreatetruecolor($numWidth, $numHeight);
|
274 |
+
}else if($this->arrOriginalDetails['mime']=="image/png"){
|
275 |
+
//PNG image
|
276 |
+
$this->resResizedImage = imagecreatetruecolor($numWidth, $numHeight);
|
277 |
+
imagecolortransparent($this->resResizedImage, imagecolorallocate($this->resResizedImage, 0, 0, 0));
|
278 |
+
imagealphablending($this->resResizedImage, false);
|
279 |
+
imagesavealpha($this->resResizedImage, true);
|
280 |
+
}
|
281 |
+
//update the image size details
|
282 |
+
$this->updateNewDetails();
|
283 |
+
//do the actual image resize
|
284 |
+
if (function_exists('imagecopyresampled')) {
|
285 |
+
imagecopyresampled($this->resResizedImage, $this->resOriginalImage, 0, 0, 0, 0, $numWidth, $numHeight, $this->arrOriginalDetails[0], $this->arrOriginalDetails[1]);
|
286 |
+
} else {
|
287 |
+
imagecopyresized($this->resResizedImage, $this->resOriginalImage, 0, 0, 0, 0, $numWidth, $numHeight, $this->arrOriginalDetails[0], $this->arrOriginalDetails[1]);
|
288 |
+
}
|
289 |
+
//saves the image
|
290 |
+
$this->saveImage();
|
291 |
+
}
|
292 |
+
}
|
293 |
+
|
294 |
+
/*
|
295 |
+
*
|
296 |
+
* @Method: _imageProtect
|
297 |
+
* @Parameters: 2
|
298 |
+
* @Param-1: numWidth - Number - The width of the image in pixels
|
299 |
+
* @Param-2: numHeight - Number - The height of the image in pixes
|
300 |
+
* @Description: Checks to see if we should allow the resize to take place or not depending on the size the image will be resized to
|
301 |
+
*
|
302 |
+
*/
|
303 |
+
|
304 |
+
function _imageProtect($numWidth, $numHeight){
|
305 |
+
if($this->boolProtect AND ($numWidth > $this->arrOriginalDetails[0] OR $numHeight > $this->arrOriginalDetails[1])){
|
306 |
+
return 0;
|
307 |
+
}
|
308 |
+
return 1;
|
309 |
+
}
|
310 |
+
|
311 |
+
/*
|
312 |
+
*
|
313 |
+
* @Method: resizeToWidth
|
314 |
+
* @Parameters: 1
|
315 |
+
* @Param-1: numWidth - Number - The width to resize to in pixels
|
316 |
+
* @Description: Works out the height value to go with the width value passed, then calls the resize method.
|
317 |
+
*
|
318 |
+
*/
|
319 |
+
|
320 |
+
function resizeToWidth($numWidth){
|
321 |
+
$numHeight=(int)(($numWidth*$this->arrOriginalDetails[1])/$this->arrOriginalDetails[0]);
|
322 |
+
$this->_resize($numWidth, $numHeight);
|
323 |
+
}
|
324 |
+
|
325 |
+
/*
|
326 |
+
*
|
327 |
+
* @Method: resizeToHeight
|
328 |
+
* @Parameters: 1
|
329 |
+
* @Param-1: numHeight - Number - The height to resize to in pixels
|
330 |
+
* @Description: Works out the width value to go with the height value passed, then calls the resize method.
|
331 |
+
*
|
332 |
+
*/
|
333 |
+
|
334 |
+
function resizeToHeight($numHeight){
|
335 |
+
$numWidth=(int)(($numHeight*$this->arrOriginalDetails[0])/$this->arrOriginalDetails[1]);
|
336 |
+
$this->_resize($numWidth, $numHeight);
|
337 |
+
}
|
338 |
+
|
339 |
+
/*
|
340 |
+
*
|
341 |
+
* @Method: resizeToPercent
|
342 |
+
* @Parameters: 1
|
343 |
+
* @Param-1: numPercent - Number - The percentage you want to resize to
|
344 |
+
* @Description: Works out the width and height value to go with the percent value passed, then calls the resize method.
|
345 |
+
*
|
346 |
+
*/
|
347 |
+
|
348 |
+
function resizeToPercent($numPercent){
|
349 |
+
$numWidth = (int)(($this->arrOriginalDetails[0]/100)*$numPercent);
|
350 |
+
$numHeight = (int)(($this->arrOriginalDetails[1]/100)*$numPercent);
|
351 |
+
$this->_resize($numWidth, $numHeight);
|
352 |
+
}
|
353 |
+
|
354 |
+
/*
|
355 |
+
*
|
356 |
+
* @Method: resizeToCustom
|
357 |
+
* @Parameters: 1
|
358 |
+
* @Param-1: size - Number/Array - Either a number of array of numbers for the width and height in pixels
|
359 |
+
* @Description: Checks to see if array was passed and calls the resize method with the correct values.
|
360 |
+
*
|
361 |
+
*/
|
362 |
+
|
363 |
+
function resizeToCustom($size){
|
364 |
+
if(!is_array($size)){
|
365 |
+
$this->_resize((int)$size, (int)$size);
|
366 |
+
}else{
|
367 |
+
$this->_resize((int)$size[0], (int)$size[1]);
|
368 |
+
}
|
369 |
+
}
|
370 |
+
}
|
371 |
+
?>
|
readme.txt
ADDED
@@ -0,0 +1,50 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
=== Resize Image After Upload ===
|
2 |
+
Contributors: jepsonrae, huiz
|
3 |
+
Donate link: http://www.jepsonrae.com/
|
4 |
+
Tags: image, plugin, resize, upload
|
5 |
+
Requires at least: 2.6
|
6 |
+
Tested up to: 3.4.2
|
7 |
+
Stable tag: 1.0.0
|
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 |
+
|
23 |
+
== Installation ==
|
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
|
38 |
+
images that are to large. Height is not always an issue. Maybe in
|
39 |
+
future this option will be added.
|
40 |
+
|
41 |
+
Q. Does it keep my EXIF data?
|
42 |
+
A. No. Although it is programmatically possible to extract that data
|
43 |
+
first and put it somewhere in the metadata, which is not implemented
|
44 |
+
off course, but a possibility, the data is lost in the process of
|
45 |
+
resizing.
|
46 |
+
|
47 |
+
== Changelog ==
|
48 |
+
|
49 |
+
= 1.0 =
|
50 |
+
* Created initial plugin.
|
resize-image-after-upload.php
ADDED
@@ -0,0 +1,150 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/*
|
3 |
+
Plugin Name: Resize Image After Upload
|
4 |
+
Plugin URI: http://www.jepsonrae.com
|
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.0
|
8 |
+
Author URI: http://www.jepsonrae.com
|
9 |
+
|
10 |
+
|
11 |
+
|
12 |
+
Copyright (C) 2008 A. Huizinga (original Resize at Upload plugin)
|
13 |
+
Copyright (C) 2012 Jepson+Rae
|
14 |
+
|
15 |
+
|
16 |
+
|
17 |
+
Includes hints and code by:
|
18 |
+
Huiz.net (www.huiz.net)
|
19 |
+
Jacob Wyke (www.redvodkajelly.com)
|
20 |
+
Paolo Tresso / Pixline (http://pixline.net)
|
21 |
+
|
22 |
+
|
23 |
+
|
24 |
+
This program is free software; you can redistribute it and/or
|
25 |
+
modify it under the terms of the GNU General Public License
|
26 |
+
as published by the Free Software Foundation; either version 2
|
27 |
+
of the License, or (at your option) any later version.
|
28 |
+
|
29 |
+
This program is distributed in the hope that it will be useful,
|
30 |
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
31 |
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
32 |
+
GNU General Public License for more details.
|
33 |
+
|
34 |
+
You should have received a copy of the GNU General Public License
|
35 |
+
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 |
+
$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 |
+
|
46 |
+
|
47 |
+
/* actions */
|
48 |
+
add_action( 'admin_menu', 'jr_uploadresize_options_page' ); // add option page
|
49 |
+
if (get_option('jr_resizeupload_resize_yesno') == 'yes') {
|
50 |
+
add_action('wp_handle_upload', 'jr_uploadresize_resize'); // apply our modifications
|
51 |
+
} // if
|
52 |
+
|
53 |
+
|
54 |
+
/* add option page */
|
55 |
+
function jr_uploadresize_options_page(){
|
56 |
+
if(function_exists('add_options_page')){
|
57 |
+
add_options_page('Resize Image After Upload','Resize Image Upload','manage_options','resize-after-upload','jr_uploadresize_options');
|
58 |
+
} // if
|
59 |
+
} // function
|
60 |
+
|
61 |
+
|
62 |
+
/* the real option 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');
|
77 |
+
} // if
|
78 |
+
else {
|
79 |
+
update_option('jr_resizeupload_resize_yesno','no');
|
80 |
+
} // else
|
81 |
+
|
82 |
+
echo('<div id="message" class="updated fade"><p><strong>Your option are saved.</strong></p></div>');
|
83 |
+
} // if
|
84 |
+
|
85 |
+
|
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 |
+
|
92 |
+
echo('<div class="wrap">');
|
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 |
+
|
101 |
+
echo('<p>Set the option \'Resize\' to no if you don\'t want to resize, this way you shouldn\'t deactivate the plugin
|
102 |
+
in case you don\'t want to resize for a while.</p>');
|
103 |
+
|
104 |
+
echo('<h3>Settings</h3>
|
105 |
+
<table class="form-table">
|
106 |
+
|
107 |
+
<tr>
|
108 |
+
<td>Resize: </td>
|
109 |
+
<td>
|
110 |
+
<select name="yesno" id="yesno">
|
111 |
+
<option value="no" label="no"'); if ($yesno == 'no') echo(' selected=selected'); echo('>no</option>
|
112 |
+
<option value="yes" label="yes"'); if ($yesno == 'yes') echo(' selected=selected'); echo('>yes</option>
|
113 |
+
</select>
|
114 |
+
</td>
|
115 |
+
</tr>
|
116 |
+
|
117 |
+
<tr>
|
118 |
+
<td>Max width: </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 |
+
|
125 |
+
</table>');
|
126 |
+
|
127 |
+
echo('<p class="submit">
|
128 |
+
<input type="hidden" name="action" value="update" />
|
129 |
+
<input type="submit" name="jr_options_update" value="Update Options »" />
|
130 |
+
</p>
|
131 |
+
</form>');
|
132 |
+
|
133 |
+
echo('</div>');
|
134 |
+
}
|
135 |
+
|
136 |
+
|
137 |
+
|
138 |
+
/* This function will apply changes to the uploaded file */
|
139 |
+
function jr_uploadresize_resize($array){
|
140 |
+
// $array contains file, url, type
|
141 |
+
if ($array['type'] == 'image/jpeg' OR $array['type'] == 'image/gif' OR $array['type'] == 'image/png') {
|
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 |
+
?>
|
screenshot-1.png
ADDED
Binary file
|