1
1
<?php
2
2
3
3
/**
4
- * hacked up version of php-respimg < https://github.com/nwtn/php-respimg>
4
+ * Hacked up version of php-respimg: https://github.com/nwtn/php-respimg
5
5
*
6
6
* @package wp-respimg
7
7
* @version 0.0.1
@@ -35,9 +35,10 @@ class Respimg extends Imagick {
35
35
*
36
36
* @access public
37
37
*
38
- * @param integer $columns The number of columns in the output image. 0 = maintain aspect ratio based on $rows.
39
- * @param integer $rows The number of rows in the output image. 0 = maintain aspect ratio based on $columns.
40
- * @param bool $optim Whether you intend to perform optimization on the resulting image. Note that setting this to `true` doesn’t actually perform any optimization.
38
+ * @param integer $columns The number of columns in the output image. 0 = maintain aspect ratio based on $rows.
39
+ * @param integer $rows The number of rows in the output image. 0 = maintain aspect ratio based on $columns.
40
+ * @param bool $optim Whether you intend to perform optimization on the resulting image.
41
+ * Note that setting this to 'true' doesn't actually perform any optimization.
41
42
*/
42
43
43
44
public function smartResize ( $ columns , $ rows , $ optim = false ) {
@@ -61,41 +62,41 @@ public function smartResize( $columns, $rows, $optim = false ) {
61
62
if ( ! $ optim ) {
62
63
$ this ->stripImage ();
63
64
}
64
-
65
65
}
66
66
67
-
68
67
/**
69
68
* Changes the size of an image to the given dimensions and removes any associated profiles.
70
69
*
71
70
* `thumbnailImage` changes the size of an image to the given dimensions and
72
- * removes any associated profiles. The goal is to produce small low cost
71
+ * removes any associated profiles. The goal is to produce small low cost
73
72
* thumbnail images suited for display on the Web.
74
73
*
75
74
* With the original Imagick thumbnailImage implementation, there is no way to choose a
76
75
* resampling filter. This class recreates Imagick’s C implementation and adds this
77
76
* additional feature.
78
77
*
79
- * Note: < https://github.com/mkoppanen/imagick/issues/90> has been filed for this issue.
78
+ * Note: https://github.com/mkoppanen/imagick/issues/90 has been filed for this issue.
80
79
*
81
80
* @access public
82
81
*
83
- * @param integer $columns The number of columns in the output image. 0 = maintain aspect ratio based on $rows.
84
- * @param integer $rows The number of rows in the output image. 0 = maintain aspect ratio based on $columns.
85
- * @param bool $bestfit Treat $columns and $rows as a bounding box in which to fit the image.
86
- * @param bool $fill Fill in the bounding box with the background colour.
87
- * @param integer $filter The resampling filter to use. Refer to the list of filter constants at <http://php.net/manual/en/imagick.constants.php>.
82
+ * @param integer $columns The number of columns in the output image. 0 = maintain aspect ratio based on $rows.
83
+ * @param integer $rows The number of rows in the output image. 0 = maintain aspect ratio based on $columns.
84
+ * @param bool $bestfit Treat $columns and $rows as a bounding box in which to fit the image.
85
+ * @param bool $fill Fill in the bounding box with the background colour.
86
+ * @param integer $filter The resampling filter to use. Refer to the list of filter constants at <http://php.net/manual/en/imagick.constants.php>.
88
87
*
89
- * @return bool Indicates whether the operation was performed successfully.
88
+ * @return bool Indicates whether the operation was performed successfully.
90
89
*/
91
90
92
91
public function thumbnailImage ( $ columns , $ rows , $ bestfit = false , $ fill = false , $ filter = Imagick::FILTER_TRIANGLE ) {
93
92
94
- // sample factor; defined in original ImageMagick thumbnailImage function
95
- // the scale to which the image should be resized using the `sample` function
93
+ /*
94
+ * Sample factor; defined in original ImageMagick thumbnailImage function
95
+ * the scale to which the image should be resized using the 'sample' function.
96
+ */
96
97
$ SampleFactor = 5 ;
97
98
98
- // filter whitelist
99
+ // Filter whitelist.
99
100
$ filters = array (
100
101
Imagick::FILTER_POINT ,
101
102
Imagick::FILTER_BOX ,
@@ -114,23 +115,23 @@ public function thumbnailImage( $columns, $rows, $bestfit = false, $fill = false
114
115
Imagick::FILTER_SINC
115
116
);
116
117
117
- // Parse parameters given to function
118
+ // Parse parameters given to function.
118
119
$ columns = (double ) $ columns ;
119
120
$ rows = (double ) $ rows ;
120
121
$ bestfit = (bool ) $ bestfit ;
121
122
$ fill = (bool ) $ fill ;
122
123
123
- // We can’t resize to (0,0)
124
+ // We can’t resize to (0,0).
124
125
if ( $ rows < 1 && $ columns < 1 ) {
125
126
return false ;
126
127
}
127
128
128
- // Set a default filter if an acceptable one wasn’t passed
129
+ // Set a default filter if an acceptable one wasn’t passed.
129
130
if ( ! in_array ( $ filter , $ filters ) ) {
130
131
$ filter = Imagick::FILTER_TRIANGLE ;
131
132
}
132
133
133
- // figure out the output width and height
134
+ // Figure out the output width and height.
134
135
$ width = (double ) $ this ->getImageWidth ();
135
136
$ height = (double ) $ this ->getImageHeight ();
136
137
$ new_width = $ columns ;
@@ -144,8 +145,10 @@ public function thumbnailImage( $columns, $rows, $bestfit = false, $fill = false
144
145
$ new_width = round ( $ y_factor * $ width );
145
146
}
146
147
147
- // if bestfit is true, the new_width/new_height of the image will be different than
148
- // the columns/rows parameters; those will define a bounding box in which the image will be fit
148
+ /*
149
+ * If bestfit is true, the new_width/new_height of the image will be different than
150
+ * the columns/rows parameters; those will define a bounding box in which the image will be fit.
151
+ */
149
152
if ( $ bestfit && $ x_factor > $ y_factor ) {
150
153
$ x_factor = $ y_factor ;
151
154
$ new_width = round ( $ y_factor * $ width );
@@ -160,8 +163,10 @@ public function thumbnailImage( $columns, $rows, $bestfit = false, $fill = false
160
163
$ new_height = 1 ;
161
164
}
162
165
163
- // if we’re resizing the image to more than about 1/3 it’s original size
164
- // then just use the resize function
166
+ /*
167
+ * If we’re resizing the image to more than about 1/3 it’s original size
168
+ * then just use the resize function.
169
+ */
165
170
if ( ( $ x_factor * $ y_factor ) > 0.1 ) {
166
171
$ this ->resizeImage ( $ new_width , $ new_height , $ filter , 1 );
167
172
@@ -215,8 +220,10 @@ public function thumbnailImage( $columns, $rows, $bestfit = false, $fill = false
215
220
$ this ->setImageProperty ( 'Thumb::Document::Pages ' , '' );
216
221
}
217
222
218
- // In case user wants to fill use extent for it rather than creating a new canvas
219
- // …fill out the bounding box
223
+ /*
224
+ * In case user wants to fill use extent for it rather than creating a new canvas
225
+ * fill out the bounding box.
226
+ */
220
227
if ( $ bestfit && $ fill && ( $ new_width != $ columns || $ new_height != $ rows ) ) {
221
228
$ extent_x = 0 ;
222
229
$ extent_y = 0 ;
@@ -233,7 +240,5 @@ public function thumbnailImage( $columns, $rows, $bestfit = false, $fill = false
233
240
}
234
241
235
242
return true ;
236
-
237
243
}
238
-
239
244
}
0 commit comments