8000 Add documentation and a test case · libvips/php-vips@645b93f · GitHub
[go: up one dir, main page]

Skip to content

Commit 645b93f

Browse files
committed
Add documentation and a test case
1 parent 6c07098 commit 645b93f

File tree

2 files changed

+59
-0
lines changed

2 files changed

+59
-0
lines changed

src/Image.php

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,44 @@
374374
* If you want to avoid the copies, you'll need to call drawing operations
375375
* yourself.
376376
*
377+
* # Thumbnailing
378+
*
379+
* The thumbnailing functionality is implemented by `Vips\Image::thumbnail` and
380+
* `Vips\Image::thumbnail_buffer` (which thumbnails an image held as a string).
381+
*
382+
* You could write:
383+
* ```php
384+
* $filename = 'image.jpg';
385+
* $image = Vips\Image::thumbnail($filename, 200, ['height' => 200]);
386+
* $image->writeToFile('my-thumbnail.jpg');
387+
* ```
388+
*
389+
* # Resample
390+
*
391+
* There are three types of operation in this section.
392+
*
393+
* First, `->affine()` applies an affine transform to an image.
394+
* This is any sort of 2D transform which preserves straight lines;
395+
* so any combination of stretch, sheer, rotate and translate.
396+
* You supply an interpolator for it to use to generate pixels
397+
* (@see Image::newInterpolator()). It will not produce good results for
398+
* very large shrinks: you'll see aliasing.
399+
*
400+
* `->reduce()` is like `->affine()`, but it can only shrink images,
401+
* it can't enlarge, rotate, or skew.
402+
* It's very fast and uses an adaptive kernel (@see Kernel for possible values)
403+
* for interpolation. Again, it will give poor results for large size reductions.
404+
*
405+
* `->shrink()` is a fast block shrinker. It can quickly reduce images by large
406+
* integer factors. It will give poor results for small size reductions:
407+
* again, you'll see aliasing.
408+
*
409+
* Next, `->resize()` specialises in the common task of image reduce and enlarge.
410+
* It strings together combinations of `->shrink()`, `->reduce()`, `->affine()`
411+
* and others to implement a general, high-quality image resizer.
412+
*
413+
* Finally, `->mapim()` can apply arbitrary 2D image transforms to an image.
414+
*
377415
* # Expansions
378416
*
379417
* Some vips operators take an enum to select an action, for example
@@ -817,6 +855,13 @@ public static function newFromArray(
817855
* Make an interpolator from a name.
818856
*
819857
* @param string $name Name of the interpolator.
858+
* Possible interpolators are:
859+
* - `'nearest'`: Use nearest neighbour interpolation.
860+
* - `'bicubic'`: Use bicubic interpolation.
861+
* - `'bilinear'`: Use bilinear interpolation (the default).
862+
* - `'nohalo'`: Use Nohalo interpolation.
863+
* - `'lbb'`: Use LBB interpolation.
864+
* - `'vsqbs'`: Use the VSQBS interpolation.
820865
*
821866
* @return resource|null The interpolator, or null on error.
822867
*/

tests/new.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,20 @@ public function testVipsCopyMemory()
9191
$this->assertEquals($image1->avg(), $image2->avg());
9292
}
9393

94+
public function testVipsNewInterpolator()
95+
{
96+
$filename = dirname(__FILE__) . '/images/img_0076.jpg';
97+
$image1 = Vips\Image::newFromFile($filename);
98+
$interp = Vips\Image::newInterpolator('bicubic');
99+
$image2 = $image1->affine([2, 0, 0, 2], ['interpolate' => $interp]);
100+
101+
$widthInput = $image1->width;
102+
$widthOutput = $image2->width;
103+
104+
$this->assertNotNull($interp);
105+
$this->assertEquals($widthInput * 2, $widthOutput);
106+
}
107+
94108
}
95109

96110
/*

0 commit comments

Comments
 (0)
0