Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,14 @@
}
],
"require": {
"php" : ">=7.0.11",
"ext-vips" : ">=0.1.0"
"php": ">=7.0.11",
"ext-vips": ">=0.1.1",
"psr/log": "^1.0.1"
},
"require-dev": {
"phpunit/phpunit": "~5.0",
"phpdocumentor/phpdocumentor" : "2.*"
"phpunit/phpunit": "^5.5",
"phpdocumentor/phpdocumentor" : "2.*",
"jakub-onderka/php-parallel-lint": "^0.9"
},
"autoload": {
"psr-4": {
Expand All @@ -34,9 +36,18 @@
"Jcupitt\\Vips\\Test\\": "tests"
}
},
"provide": {
"psr/log-implementation": "1.0.0"
},
"extra": {
"branch-alias": {
"dev-master": "1.0-dev"
}
},
"scripts": {
"test": [
"parallel-lint . --exclude vendor",
"phpunit"
]
}
}
6 changes: 3 additions & 3 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 2 additions & 4 deletions examples/vips_addconst.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
#!/usr/bin/env php
<?php
<?php

include '../src/Image.php';
require __DIR__ . '/../vendor/autoload.php';

use Jcupitt\Vips;

$image = Vips\Image::newFromArray([[1, 2, 3], [4, 5, 6]]);
$image = $image->linear(1, 1);

?>
19 changes: 9 additions & 10 deletions examples/vips_bench.php
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
#!/usr/bin/env php
<?php

include '../src/Image.php';
require __DIR__ . '/../vendor/autoload.php';

use Jcupitt\Vips;

$im = Vips\Image::newFromFile($argv[1], ["access" => "sequential"]);
$im = Vips\Image::newFromFile($argv[1], ["access" => Vips\Enum\Access::SEQUENTIAL]);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Enum in the type name is a bit ugly :(

I can see an enums subdirectory makes the php-vips package look tidier, but it forces all code that uses php-vips to have this extra bit of noise in.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree. Not sure if we should keep the Enum sub-directory because of this. However we could make it look nicer if we import those classes on the top of the file (like we did in the Image class):

use Jcupitt\Vips\Enum\Access;
use Jcupitt\Vips\Enum\Kernel;

// Now we can make it look nicer:
echo Access::SEQUENTIAL;
echo Kernel::LINEAR;

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's get rid of the Enum directory. I think this is out of scope for this PR, I'll add a note to the 1.0 roadmap to look at this again.


$im = $im->crop(100, 100, $im->width - 200, $im->height - 200);

$im = $im->reduce(1.0 / 0.9, 1.0 / 0.9, ["kernel" => "linear"]);
$im = $im->reduce(1.0 / 0.9, 1.0 / 0.9, ["kernel" => Vips\Enum\Kernel::LINEAR]);

$mask = Vips\Image::newFromArray(
[[-1, -1, -1],
[-1, 16, -1],
[-1, -1, -1]], 8);
$mask = Vips\Image::newFromArray([
[-1, -1, -1],
[-1, 16, -1],
[-1, -1, -1]
], 8);
$im = $im->conv($mask);

$im->writeToFile($argv[2]);

?>
$im->writeToFile($argv[2]);
61 changes: 53 additions & 8 deletions examples/vips_class.php
Original file line number Diff line number Diff line change
@@ -1,18 +1,63 @@
#!/usr/bin/env php
<?php

include '../src/Image.php';
require __DIR__ . '/../vendor/autoload.php';

use Jcupitt\Vips;

Vips\Image::setLogging(true);

$image = Vips\Image::newFromFile($argv[1]);

echo "width = ", $image->width, "\n";
const LOG_FORMAT = "[%datetime%] %level_name%: %message% %context%\n";
const DATE_FORMAT = "Y-m-d\TH:i:sP";

Vips\Image::setLogger(new class implements Psr\Log\LoggerInterface {
// Use the LoggerTait so that we only have to implement the generic log method.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo: LoggerTrait

use Psr\Log\LoggerTrait;

/**
* Logs with an arbitrary level.
*
* @param mixed $level
* @param string $message
* @param array $context
*
* @return void
*/
public function log($level, $message, array $context = [])
{
// `Vips\Image` to string convert
array_walk_recursive($context, function (&$value) {
if ($value instanceof Vips\Image) {
// TODO: Should we override __toString() in `Vips\Image` instead
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I forget to include this TODO in the pull request description. I've implemented some basic __toString() in here, maybe we should put this in the Image class to let users use $imageText = (string)$image;.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, that would look nicer in Image.

$value = [
'instance' => 'Vips\Image',
'width' => $value->width,
'height' => $value->height,
'bands' => $value->bands,
'format' => $value->format,
'interpretation' => $value->interpretation,
];
}
});

$strParams = [
'%datetime%' => date(DATE_FORMAT),
'%level_name%' => $level,
'%message%' => $message,
'%context%' => json_encode(
$context,
JSON_UNESCAPED_SLASHES |
JSON_UNESCAPED_UNICODE |
JSON_PRESERVE_ZERO_FRACTION
),
];

echo strtr(LOG_FORMAT, $strParams);
}
});

$image = Vips\Image::newFromFile($argv[1]);

echo "width = " . $image->width . "\n";

$image = $image->invert();

$image->writeToFile($argv[2]);

?>
Loading