Adding example connector.
This commit is contained in:
parent
71513995b8
commit
4756e9685f
17
composer.json
Normal file
17
composer.json
Normal file
@ -0,0 +1,17 @@
|
||||
{
|
||||
"name": "sergio/exec_libvips_php",
|
||||
"type": "library",
|
||||
"license": "proprietary",
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Sergio\\ExecLibvipsPhp\\": "src/"
|
||||
}
|
||||
},
|
||||
"authors": [
|
||||
{
|
||||
"name": "Sergiotarxz",
|
||||
"email": "sergiotarxz@posteo.net"
|
||||
}
|
||||
],
|
||||
"require": {}
|
||||
}
|
18
composer.lock
generated
Normal file
18
composer.lock
generated
Normal file
@ -0,0 +1,18 @@
|
||||
{
|
||||
"_readme": [
|
||||
"This file locks the dependencies of your project to a known state",
|
||||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
||||
"This file is @generated automatically"
|
||||
],
|
||||
"content-hash": "2b1115d0fe6887ac144d9b0248d72ced",
|
||||
"packages": [],
|
||||
"packages-dev": [],
|
||||
"aliases": [],
|
||||
"minimum-stability": "stable",
|
||||
"stability-flags": [],
|
||||
"prefer-stable": false,
|
||||
"prefer-lowest": false,
|
||||
"platform": [],
|
||||
"platform-dev": [],
|
||||
"plugin-api-version": "2.1.0"
|
||||
}
|
36
src/index.php
Normal file
36
src/index.php
Normal file
@ -0,0 +1,36 @@
|
||||
<?php
|
||||
namespace Sergio\ExecLibvipsPhp;
|
||||
use Exception;
|
||||
|
||||
function transform(string $socketLocation, string $inputFile, string $outputFile,
|
||||
int $cyan, int $magenta, int $yellow, int $black, int $blackType,
|
||||
int $colorType): array {
|
||||
$socket = socket_create(AF_UNIX, SOCK_STREAM, 0);
|
||||
if ($socket === false) {
|
||||
throw new Exception(socket_last_error());
|
||||
}
|
||||
if(socket_connect($socket, $socketLocation) === false) {
|
||||
throw new Exception("Unable to connect to specified socket location $socketLocation");
|
||||
}
|
||||
$json = json_encode([
|
||||
"input_file" => $inputFile,
|
||||
"output_file" => $outputFile,
|
||||
"cyan" => $cyan,
|
||||
"magenta" => $magenta,
|
||||
"black" => $black,
|
||||
"yellow" => $yellow,
|
||||
"colorType" => $colorType,
|
||||
"blackType" => $blackType,
|
||||
]);
|
||||
$json_len = strlen($json);
|
||||
socket_write($socket, pack("J", $json_len), 8);
|
||||
socket_write($socket, $json, $json_len);
|
||||
$json_len = "";
|
||||
socket_recv($socket, $json_len, 8, MSG_WAITALL);
|
||||
$json_len = unpack("J", $json_len)[1];
|
||||
$json = "";
|
||||
socket_recv($socket, $json, $json_len, MSG_WAITALL);
|
||||
$json = json_decode($json, true);
|
||||
var_dump($json);
|
||||
return $json;
|
||||
}
|
Loading…
Reference in New Issue
Block a user