Skip to content

Commit 2feeb9a

Browse files
committed
chore: Generate autodoc methods for source/target
feat: Add benchmark example
1 parent 1a5f7f0 commit 2feeb9a

8 files changed

+225
-69
lines changed

examples/generate_phpdoc.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@
3131
GValue.array_int_type: 'integer[]|integer',
3232
GValue.array_double_type: 'float[]|float',
3333
GValue.array_image_type: 'Image[]|Image',
34-
GValue.blob_type: 'string'
34+
GValue.blob_type: 'string',
35+
GValue.source_type: 'VipsSource',
36+
GValue.target_type: 'VipsTarget'
3537
}
3638

3739
# php result type names are different, annoyingly, and very restricted
@@ -48,7 +50,9 @@
4850
GValue.array_int_type: 'array',
4951
GValue.array_double_type: 'array',
5052
GValue.array_image_type: 'array',
51-
GValue.blob_type: 'string'
53+
GValue.blob_type: 'string',
54+
GValue.source_type: 'VipsSource',
55+
GValue.target_type: 'VipsTarget'
5256
}
5357

5458
# values for VipsArgumentFlags

examples/streaming-bench.php

+131
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
#!/usr/bin/env php
2+
<?php
3+
4+
use Jcupitt\Vips\Config;
5+
use Jcupitt\Vips\Image;
6+
use Jcupitt\Vips\VipsSource;
7+
use Jcupitt\Vips\VipsSourceResource;
8+
use Jcupitt\Vips\VipsTarget;
9+
use Jcupitt\Vips\VipsTargetResource;
10+
11+
require dirname(__DIR__) . '/vendor/autoload.php';
12+
13+
$doBenchmark = static function () {
14+
$sourceOptions = ['access' => 'sequential'];
15+
$sourceOptionString = 'access=sequential';
16+
$iterations = 100;
17+
$targetWidth = 100.0;
18+
$targetSuffix = '.jpg';
19+
$targetOptions = ['optimize-coding' => true, 'strip' => true, 'Q' => 100, 'profile' => 'srgb'];
20+
$targetFile = dirname(__DIR__) . "/tests/images/target.jpg";
21+
$sourceFile = dirname(__DIR__) . '/tests/images/img_0076.jpg';
22+
23+
### Callbacks
24+
$start = microtime(true);
25+
26+
for ($i = 0; $i < $iterations; $i++) {
27+
$source = new VipsSourceResource(fopen($sourceFile, 'rb'));
28+
$target = new VipsTargetResource(fopen($targetFile, 'wb+'));
29+
$image = Image::newFromSource($source, '', $sourceOptions);
30+
$image = $image->resize($targetWidth / $image->width);
31+
$image->writeToTarget(
32+
$target,
33+
$targetSuffix,
34+
$targetOptions
35+
);
36+
unlink($targetFile);
37+
}
38+
39+
echo (microtime(true) - $start) . ' Seconds for Streaming with callbacks' . PHP_EOL;
40+
41+
### Builtin
42+
$start = microtime(true);
43+
44+
for ($i = 0; $i < $iterations; $i++) {
45+
$source = VipsSource::newFromFile($sourceFile);
46+
$target = VipsTarget::newToFile($targetFile);
47+
$image = Image::newFromSource($source, '', $sourceOptions);
48+
$image = $image->resize($targetWidth / $image->width);
49+
$image->writeToTarget(
50+
$target,
51+
$targetSuffix,
52+
$targetOptions
53+
);
54+
unlink($targetFile);
55+
}
56+
57+
echo (microtime(true) - $start) . ' Seconds for Streaming with builtin source/target' . PHP_EOL;
58+
59+
### Callbacks Thumbnail
60+
$start = microtime(true);
61+
62+
for ($i = 0; $i < $iterations; $i++) {
63+
$source = new VipsSourceResource(fopen($sourceFile, 'rb'));
64+
$target = new VipsTargetResource(fopen($targetFile, 'wb+'));
65+
$image = Image::thumbnail_source($source, $targetWidth);
66+
$image->writeToTarget(
67+
$target,
68+
$targetSuffix,
69+
$targetOptions
70+
);
71+
unlink($targetFile);
72+
}
73+
74+
echo (microtime(true) - $start) . ' Seconds for Streaming Thumbnail with callbacks' . PHP_EOL;
75+
76+
### Builtin Thumbnail
77+
$start = microtime(true);
78+
79+
for ($i = 0; $i < $iterations; $i++) {
80+
$source = VipsSource::newFromFile($sourceFile);
81+
$target = VipsTarget::newToFile($targetFile);
82+
$image = Image::thumbnail_source($source, $targetWidth);
83+
$image->writeToTarget(
84+
$target,
85+
$targetSuffix,
86+
$targetOptions
87+
);
88+
unlink($targetFile);
89+
}
90+
91+
echo (microtime(true) - $start) . ' Seconds for Streaming Thumbnail with builtin source/target' . PHP_EOL;
92+
93+
### Thumbnail
94+
$start = microtime(true);
95+
96+
for ($i = 0; $i < $iterations; $i++) {
97+
$image = Image::thumbnail($sourceFile . "[$sourceOptionString]", $targetWidth);
98+
$image->writeToFile(
99+
$targetFile,
100+
$targetOptions
101+
);
102+
unlink($targetFile);
103+
}
104+
105+
echo (microtime(true) - $start) . ' Seconds for Thumbnail API' . PHP_EOL;
106+
107+
### Classic
108+
$start = microtime(true);
109+
110+
for ($i = 0; $i < $iterations; $i++) {
111+
$image = Image::newFromFile($sourceFile, $sourceOptions);
112+
$image = $image->resize($targetWidth / $image->width);
113+
$image->writeToFile(
114+
$targetFile,
115+
$targetOptions
116+
);
117+
unlink($targetFile);
118+
}
119+
120+
echo (microtime(true) - $start) . ' Seconds for Classic API' . PHP_EOL;
121+
};
122+
123+
$doBenchmark();
124+
125+
echo "=== NOW NO CACHE ===" . PHP_EOL;
126+
127+
Config::cacheSetMax(0);
128+
Config::cacheSetMaxFiles(0);
129+
Config::cacheSetMaxMem(0);
130+
131+
$doBenchmark();

src/ForeignDzLayout.php

-1
Original file line numberDiff line numberDiff line change
@@ -53,5 +53,4 @@ abstract class ForeignDzLayout
5353
const ZOOMIFY = 'zoomify';
5454
const GOOGLE = 'google';
5555
const IIIF = 'iiif';
56-
const IIIF3 = 'iiif3';
5756
}

src/GsfOutputCsvQuotingMode.php

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<?php
2+
3+
/**
4+
* This file was generated automatically. Do not edit!
5+
*
6+
* PHP version 7
7+
*
8+
* LICENSE:
9+
*
10+
* Copyright (c) 2016 John Cupitt
11+
*
12+
* Permission is hereby granted, free of charge, to any person obtaining
13+
* a copy of this software and associated documentation files (the
14+
* "Software"), to deal in the Software without restriction, including
15+
* without limitation the rights to use, copy, modify, merge, publish,
16+
* distribute, sublicense, and/or sell copies of the Software, and to
17+
* permit persons to whom the Software is furnished to do so, subject to
18+
* the following conditions:
19+
*
20+
* The above copyright notice and this permission notice shall be
21+
* included in all copies or substantial portions of the Software.
22+
*
23+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24+
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25+
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26+
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
27+
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
28+
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
29+
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
30+
*
31+
* @category Images
32+
* @package Jcupitt\Vips
33+
* @author John Cupitt <jcupitt@gmail.com>
34+
* @copyright 2016 John Cupitt
35+
* @license https://opensource.org/licenses/MIT MIT
36+
* @link https://github.com/jcupitt/php-vips
37+
*/
38+
39+
namespace Jcupitt\Vips;
40+
41+
/**
42+
* The GsfOutputCsvQuotingMode enum.
43+
* @category Images
44+
* @package Jcupitt\Vips
45+
* @author John Cupitt <jcupitt@gmail.com>
46+
* @copyright 2016 John Cupitt
47+
* @license https://opensource.org/licenses/MIT MIT
48+
* @link https://github.com/jcupitt/php-vips
49+
*/
50+
abstract class GsfOutputCsvQuotingMode
51+
{
52+
const NEVER = 'never';
53+
const AUTO = 'auto';
54+
}

0 commit comments

Comments
 (0)