-
Notifications
You must be signed in to change notification settings - Fork 28
Improved logging, enumerations and more #15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| 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); | ||
|
|
||
| ?> |
| 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]); | ||
|
|
||
| $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]); | ||
| 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. | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I forget to include this There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree, that would look nicer in |
||
| $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]); | ||
|
|
||
| ?> | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
Enumin 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.
There was a problem hiding this comment.
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
Enumsub-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):There was a problem hiding this comment.
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
Enumdirectory. 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.