11<?php
2-
3- /* This file tries to make a nice API over the raw `vips_call` thing defined
4- * in C.
2+ /**
3+ * php-vips is a php binding for the vips image processing library.
54 */
65
76if (!extension_loaded ("vips " )) {
87 dl ('vips. ' . PHP_SHLIB_SUFFIX );
98}
109
10+ /**
11+ * The VImage class represents an image.
12+ */
1113class VImage implements ArrayAccess
1214{
1315 /* The resource for the underlying VipsImage.
1416 */
1517 private $ image ;
1618
17- function __construct ($ image )
19+ /**
20+ * Wrap a VImage around an underlying vips resource.
21+ *
22+ * Don't call this yourself, users should stick to (for example)
23+ * VImage::new_from_file().
24+ *
25+ * @param resource $image The underlying vips image resource that this
26+ * class should wrap.
27+ *
28+ * @return a new VImage.
29+ */
30+ public function __construct ($ image )
1831 {
1932 $ this ->image = $ image ;
2033 }
@@ -130,13 +143,31 @@ private static function wrap($result)
130143 return $ result ;
131144 }
132145
146+ /**
147+ * Create a new VImage from a file on disc.
148+ *
149+ * @param string $filename The file to open.
150+ * @param array $options Any options to pass on to the load operation.
151+ *
152+ * @return A new VImage.
153+ */
133154 public static function new_from_file ($ filename , $ options = [])
134155 {
135156 $ options = self ::unwrap ($ options );
136157 $ result = vips_image_new_from_file ($ filename , $ options );
137158 return self ::wrap ($ result );
138159 }
139160
161+ /**
162+ * Create a new VImage from a compressed image held as a string.
163+ *
164+ * @param string $buffer The formatted image to open.
165+ * @param string $option_string Any text-style options to pass to the
166+ * selected loader.
167+ * @param array $options Any options to pass on to the load operation.
168+ *
169+ * @return A new VImage.
170+ */
140171 public static function new_from_buffer ($ buffer ,
141172 $ option_string = "" , $ options = [])
142173 {
@@ -145,37 +176,93 @@ public static function new_from_buffer($buffer,
145176 return self ::wrap ($ result );
146177 }
147178
179+ /**
180+ * Create a new VImage from a php array.
181+ *
182+ * 2D arrays become 2D images. 1D arrays become 2D images with height 1.
183+ *
184+ * @param array $array The array to make the image from.
185+ * @param double $scale The "scale" metadata item. Useful for integer
186+ * convolution masks.
187+ * @param double $offset The "offset" metadata item. Useful for integer
188+ * convolution masks.
189+ *
190+ * @return A new VImage.
191+ */
148192 public static function new_from_array ($ array , $ scale = 1 , $ offset = 0 )
149193 {
150194 $ result = vips_image_new_from_array ($ array , $ scale , $ offset );
151195 return self ::wrap ($ result );
152196 }
153197
198+ /**
199+ * Write an image to a file.
200+ *
201+ * @param string $filename The file to write the image to.
202+ * @param array $options Any options to pass on to the selected save
203+ * operation.
204+ *
205+ * @return bool TRUE for success and FALSE for failure.
206+ */
154207 public function write_to_file ($ filename , $ options = [])
155208 {
156209 $ options = self ::unwrap ($ options );
157210 $ result = vips_image_write_to_file ($ this ->image , $ filename , $ options );
158211 return self ::wrap ($ result );
159212 }
160213
214+ /**
215+ * Write an image to a formatted string.
216+ *
217+ * @param string $suffix The file type suffix, eg. ".jpg".
218+ * @param array $options Any options to pass on to the selected save
219+ * operation.
220+ *
221+ * @return string The formatted image.
222+ */
161223 public function write_to_buffer ($ suffix , $ options = [])
162224 {
163225 $ options = self ::unwrap ($ options );
164226 $ result = vips_image_write_to_buffer ($ this ->image , $ suffix , $ options );
165227 return self ::wrap ($ result );
166228 }
167229
230+ /**
231+ * Get any property from the underlying image.
232+ *
233+ * @param string $name The property name.
234+ *
235+ * @return mixed
236+ */
168237 public function __get ($ name )
169238 {
170239 $ result = vips_image_get ($ this ->image , $ name );
171240 return self ::wrap ($ result );
172241 }
173242
243+ /**
244+ * Set any property on the underlying image.
245+ *
246+ * @param string $name The property name.
247+ * @param mixed $value The value to set for this property.
248+ *
249+ * @return void
250+ */
174251 public function __set ($ name , $ value )
175252 {
176253 vips_image_set ($ this ->image , $ name , $ value );
177254 }
178255
256+ /**
257+ * Call any vips operation.
258+ *
259+ * @param string $name The operation name.
260+ * @param VImage $instance The instance this operation is being invoked
261+ * from.
262+ * @param mixed[] $arguments An array of arguments to pass to the operation.
263+ *
264+ * @return mixed The result(s) of the operation.
265+ */
179266 public static function call ($ name , $ instance , $ arguments )
180267 {
181268 /*
@@ -208,11 +295,17 @@ private function call_enum($other, $base, $op, $options = [])
208295 }
209296 }
210297
298+ /**
299+ * Call any vips operation as an instance method.
300+ */
211301 public function __call ($ name , $ arguments )
212302 {
213303 return self ::call ($ name , $ this , $ arguments );
214304 }
215305
306+ /**
307+ * Call any vips operation as a class method.
308+ */
216309 public static function __callStatic ($ name , $ arguments )
217310 {
218311 return self ::call ($ name , NULL , $ arguments );
@@ -245,6 +338,15 @@ public function offsetUnset($offset)
245338 * speedup.
246339 */
247340
341+ /**
342+ * Add to this image.
343+ *
344+ * @param int|double|int[]|double[]|VImage $other The thing to add to this
345+ * image.
346+ * @param array $options Any options to pass on to the add operation.
347+ *
348+ * @return VImage A new image.
349+ */
248350 public function add ($ other , $ options = [])
249351 {
250352 if ($ other instanceof VImage) {
@@ -263,7 +365,7 @@ public function subtract($other, $options = [])
263365 }
264366 else {
265367 $ other = map_numeric ($ other , function ($ value ) {
266- return -1 * $ value ;
368+ return -1 * $ value ;
267369 });
268370 return self ::linear ($ this , 1 , $ other , $ options );
269371 }
@@ -287,7 +389,7 @@ public function divide($other, $options = [])
287389 }
288390 else {
289391 $ other = map_numeric ($ other , function ($ value ) {
290- return $ value ** -1 ;
392+ return $ value ** -1 ;
291393 });
292394 return self ::linear ($ this , $ other , 0 , $ options );
293395 }
0 commit comments