11<?php
22
33/**
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
55 *
66 * @package wp-respimg
77 * @version 0.0.1
@@ -35,9 +35,10 @@ class Respimg extends Imagick {
3535 *
3636 * @access public
3737 *
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.
4142 */
4243
4344 public function smartResize ( $ columns , $ rows , $ optim = false ) {
@@ -61,41 +62,41 @@ public function smartResize( $columns, $rows, $optim = false ) {
6162 if ( ! $ optim ) {
6263 $ this ->stripImage ();
6364 }
64-
6565 }
6666
67-
6867 /**
6968 * Changes the size of an image to the given dimensions and removes any associated profiles.
7069 *
7170 * `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
7372 * thumbnail images suited for display on the Web.
7473 *
7574 * With the original Imagick thumbnailImage implementation, there is no way to choose a
7675 * resampling filter. This class recreates Imagick’s C implementation and adds this
7776 * additional feature.
7877 *
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.
8079 *
8180 * @access public
8281 *
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>.
8887 *
89- * @return bool Indicates whether the operation was performed successfully.
88+ * @return bool Indicates whether the operation was performed successfully.
9089 */
9190
9291 public function thumbnailImage ( $ columns , $ rows , $ bestfit = false , $ fill = false , $ filter = Imagick::FILTER_TRIANGLE ) {
9392
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+ */
9697 $ SampleFactor = 5 ;
9798
98- // filter whitelist
99+ // Filter whitelist.
99100 $ filters = array (
100101 Imagick::FILTER_POINT ,
101102 Imagick::FILTER_BOX ,
@@ -114,23 +115,23 @@ public function thumbnailImage( $columns, $rows, $bestfit = false, $fill = false
114115 Imagick::FILTER_SINC
115116 );
116117
117- // Parse parameters given to function
118+ // Parse parameters given to function.
118119 $ columns = (double ) $ columns ;
119120 $ rows = (double ) $ rows ;
120121 $ bestfit = (bool ) $ bestfit ;
121122 $ fill = (bool ) $ fill ;
122123
123- // We can’t resize to (0,0)
124+ // We can’t resize to (0,0).
124125 if ( $ rows < 1 && $ columns < 1 ) {
125126 return false ;
126127 }
127128
128- // Set a default filter if an acceptable one wasn’t passed
129+ // Set a default filter if an acceptable one wasn’t passed.
129130 if ( ! in_array ( $ filter , $ filters ) ) {
130131 $ filter = Imagick::FILTER_TRIANGLE ;
131132 }
132133
133- // figure out the output width and height
134+ // Figure out the output width and height.
134135 $ width = (double ) $ this ->getImageWidth ();
135136 $ height = (double ) $ this ->getImageHeight ();
136137 $ new_width = $ columns ;
@@ -144,8 +145,10 @@ public function thumbnailImage( $columns, $rows, $bestfit = false, $fill = false
144145 $ new_width = round ( $ y_factor * $ width );
145146 }
146147
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+ */
149152 if ( $ bestfit && $ x_factor > $ y_factor ) {
150153 $ x_factor = $ y_factor ;
151154 $ new_width = round ( $ y_factor * $ width );
@@ -160,8 +163,10 @@ public function thumbnailImage( $columns, $rows, $bestfit = false, $fill = false
160163 $ new_height = 1 ;
161164 }
162165
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+ */
165170 if ( ( $ x_factor * $ y_factor ) > 0.1 ) {
166171 $ this ->resizeImage ( $ new_width , $ new_height , $ filter , 1 );
167172
@@ -215,8 +220,10 @@ public function thumbnailImage( $columns, $rows, $bestfit = false, $fill = false
215220 $ this ->setImageProperty ( 'Thumb::Document::Pages ' , '' );
216221 }
217222
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+ */
220227 if ( $ bestfit && $ fill && ( $ new_width != $ columns || $ new_height != $ rows ) ) {
221228 $ extent_x = 0 ;
222229 $ extent_y = 0 ;
@@ -233,7 +240,5 @@ public function thumbnailImage( $columns, $rows, $bestfit = false, $fill = false
233240 }
234241
235242 return true ;
236-
237243 }
238-
239244}
0 commit comments