From 2d3f4b644a2f714bb940d586d50508df14a7dbc8 Mon Sep 17 00:00:00 2001 From: Vincent Vanwaelscappel Date: Mon, 6 Sep 2021 20:09:06 +0200 Subject: [PATCH] wip #4666 @0.5 --- app/Jobs/ProcessFluidbook.php | 43 +++++--------- composer.json | 5 +- composer.lock | 103 +++++++++++++++++++++++++--------- 3 files changed, 93 insertions(+), 58 deletions(-) diff --git a/app/Jobs/ProcessFluidbook.php b/app/Jobs/ProcessFluidbook.php index 57ea47d..3cacc9d 100644 --- a/app/Jobs/ProcessFluidbook.php +++ b/app/Jobs/ProcessFluidbook.php @@ -3,6 +3,8 @@ namespace App\Jobs; use Cubist\Util\CommandLine; +use Fluidbook\Tools\FluidbookTools; +use Fluidbook\Tools\PDF\Document; use Illuminate\Bus\Queueable; use Illuminate\Contracts\Queue\ShouldBeUnique; use Illuminate\Contracts\Queue\ShouldQueue; @@ -14,13 +16,12 @@ class ProcessFluidbook implements ShouldQueue, ShouldBeUnique { use Dispatchable, InteractsWithQueue, Queueable, SerializesModels; + /** + * @var Document + */ protected $in; protected $out; - protected $pages; - protected $width; - protected $height; - /** * Create a new job instance. * @@ -28,7 +29,7 @@ class ProcessFluidbook implements ShouldQueue, ShouldBeUnique */ public function __construct() { - $this->in = storage_path('fluidbook/in/'); + $this->in = new Document(storage_path('fluidbook/in/in.pdf')); $this->out = storage_path('fluidbook/out/'); } @@ -40,8 +41,7 @@ class ProcessFluidbook implements ShouldQueue, ShouldBeUnique public function handle() { $this->resetOutput(); - $this->getInfos(); - $this->pdfToImages(); + $this->processPages(); $this->getTexts(); $this->getLinks(); $this->writeConfig(); @@ -54,29 +54,16 @@ class ProcessFluidbook implements ShouldQueue, ShouldBeUnique `$cmd`; } - public function getInfos() - { - $fwstk = new CommandLine(base_path('tools/fwstk.sh')); - $fwstk->setArg('--input ' . $this->in . 'in.pdf'); - $fwstk->setArg('--infos'); - $fwstk->execute(); - - $infos = $fwstk->getOutput(); - - if (preg_match('/Pages:\s*(\d+)/', $infos, $matches)) { - $this->pages = (int)$matches[1]; - } - if (preg_match('/Page 1 size:\s*([0-9.]+)[ptsx\s]+([0-9.]+)/', $infos, $matches)) { - $this->width = (float)$matches[1]; - $this->height = (float)$matches[2]; - } - - file_put_contents($this->in . '/infos.txt', $infos); - } - public function pdfToImages() + public function processPages() { - + $out = storage_path('fluidbook/convert/' . $this->in->getHash()); + $this->in->processPages($out, [ + ['format' => 'jpg', 'resolution' => '36', 'withTexts' => true, 'withGraphics' => true], + ['format' => 'jpg', 'resolution' => '150', 'withTexts' => false, 'withGraphics' => true], + ['format' => 'jpg', 'resolution' => '300', 'withTexts' => false, 'withGraphics' => true], + ['format' => 'svg', 'resolution' => '300', 'withTexts' => true, 'withGraphics' => false], + ]); } public function getTexts() diff --git a/composer.json b/composer.json index 7156ab2..e6b3f40 100644 --- a/composer.json +++ b/composer.json @@ -11,13 +11,14 @@ ], "license": "MIT", "require": { - "php": "^7.3|^8.0", + "php": "^8.0", "ext-json": "*", + "ext-redis": "*", "ext-simplexml": "*", "ext-tidy": "*", "ext-zip": "*", - "ext-redis": "*", "cubist/cms-back": "dev-master", + "fluidbook/tools": "dev-master", "fruitcake/laravel-cors": "^2.0", "guzzlehttp/guzzle": "^7.3", "laravel/framework": "^8.58", diff --git a/composer.lock b/composer.lock index bbc2d2f..47eddfd 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "90fd3102e33006c8e1bfaef9432159d3", + "content-hash": "c743f32a801dc0c163a83f8f0ff687b3", "packages": [ { "name": "asm89/stack-cors", @@ -131,16 +131,16 @@ }, { "name": "backpack/crud", - "version": "4.1.51", + "version": "4.1.52", "source": { "type": "git", "url": "https://github.com/Laravel-Backpack/CRUD.git", - "reference": "756173cf6593c3d530fca0e54831763c796e24d8" + "reference": "239e60df0436f8a817facce20a2dffcb2b6e7250" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/Laravel-Backpack/CRUD/zipball/756173cf6593c3d530fca0e54831763c796e24d8", - "reference": "756173cf6593c3d530fca0e54831763c796e24d8", + "url": "https://api.github.com/repos/Laravel-Backpack/CRUD/zipball/239e60df0436f8a817facce20a2dffcb2b6e7250", + "reference": "239e60df0436f8a817facce20a2dffcb2b6e7250", "shasum": "" }, "require": { @@ -218,9 +218,9 @@ ], "support": { "issues": "https://github.com/Laravel-Backpack/CRUD/issues", - "source": "https://github.com/Laravel-Backpack/CRUD/tree/4.1.51" + "source": "https://github.com/Laravel-Backpack/CRUD/tree/4.1.52" }, - "time": "2021-09-02T06:20:26+00:00" + "time": "2021-09-06T06:35:01+00:00" }, { "name": "backpack/logmanager", @@ -1486,13 +1486,13 @@ "source": { "type": "git", "url": "git://git.cubedesigners.com/cubist_util.git", - "reference": "4c5cd619a89e6679fca80ff84036f68c554426a7" + "reference": "12177cd5bd8abcefa708e3aabdf9985ef3e3b85d" }, "dist": { "type": "tar", - "url": "https://composer.cubedesigners.com/dist/cubist/util/cubist-util-dev-master-906685.tar", - "reference": "4c5cd619a89e6679fca80ff84036f68c554426a7", - "shasum": "b5b3518f6c33d521010f9878c31e05c2abbc9c91" + "url": "https://composer.cubedesigners.com/dist/cubist/util/cubist-util-dev-master-610682.tar", + "reference": "12177cd5bd8abcefa708e3aabdf9985ef3e3b85d", + "shasum": "91ae258076cacde665055cd5c1f7b728b95ea4e2" }, "require": { "cubist/net": "dev-master", @@ -1522,7 +1522,7 @@ } ], "description": "Utilities class", - "time": "2021-04-20T13:58:22+00:00" + "time": "2021-09-03T16:57:58+00:00" }, { "name": "cviebrock/eloquent-sluggable", @@ -2606,6 +2606,51 @@ }, "time": "2020-10-22T13:48:01+00:00" }, + { + "name": "fluidbook/tools", + "version": "dev-master", + "source": { + "type": "git", + "url": "git://git.cubedesigners.com/fluidbook_tools.git", + "reference": "fbcd179c04e2bd1061307bcabda70a9756b4217b" + }, + "dist": { + "type": "tar", + "url": "https://composer.cubedesigners.com/dist/fluidbook/tools/fluidbook-tools-dev-master-d6dc02.tar", + "reference": "fbcd179c04e2bd1061307bcabda70a9756b4217b", + "shasum": "88e7797805be96ed7a2ba0842029d42f1466d5b4" + }, + "require": { + "cubist/util": "dev-master", + "ext-dom": "*", + "ext-gd": "*", + "ext-iconv": "*", + "ext-json": "*", + "ext-libxml": "*", + "ext-mbstring": "*", + "ext-simplexml": "*", + "laravel/framework": "~5.8|^6.0|^7.0|^8.0", + "php": ">=7.0.0" + }, + "default-branch": true, + "type": "library", + "autoload": { + "psr-4": { + "Fluidbook\\Tools\\": "src" + } + }, + "license": [ + "proprietary" + ], + "authors": [ + { + "name": "Vincent Vanwaelscappel", + "email": "vincent@cubedesigners.com" + } + ], + "description": "Fluidbook Tools", + "time": "2021-09-06T17:21:56+00:00" + }, { "name": "fruitcake/laravel-cors", "version": "v2.0.4", @@ -4412,16 +4457,16 @@ }, { "name": "nesbot/carbon", - "version": "2.52.0", + "version": "2.53.1", "source": { "type": "git", "url": "https://github.com/briannesbitt/Carbon.git", - "reference": "369c0e2737c56a0f39c946dd261855255a6fccbe" + "reference": "f4655858a784988f880c1b8c7feabbf02dfdf045" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/briannesbitt/Carbon/zipball/369c0e2737c56a0f39c946dd261855255a6fccbe", - "reference": "369c0e2737c56a0f39c946dd261855255a6fccbe", + "url": "https://api.github.com/repos/briannesbitt/Carbon/zipball/f4655858a784988f880c1b8c7feabbf02dfdf045", + "reference": "f4655858a784988f880c1b8c7feabbf02dfdf045", "shasum": "" }, "require": { @@ -4433,7 +4478,7 @@ }, "require-dev": { "doctrine/orm": "^2.7", - "friendsofphp/php-cs-fixer": "^2.14 || ^3.0", + "friendsofphp/php-cs-fixer": "^3.0", "kylekatarnls/multi-tester": "^2.0", "phpmd/phpmd": "^2.9", "phpstan/extension-installer": "^1.0", @@ -4502,7 +4547,7 @@ "type": "tidelift" } ], - "time": "2021-08-14T19:10:52+00:00" + "time": "2021-09-06T09:29:23+00:00" }, { "name": "nikic/php-parser", @@ -9598,21 +9643,21 @@ }, { "name": "fakerphp/faker", - "version": "v1.15.0", + "version": "v1.16.0", "source": { "type": "git", "url": "https://github.com/FakerPHP/Faker.git", - "reference": "89c6201c74db25fa759ff16e78a4d8f32547770e" + "reference": "271d384d216e5e5c468a6b28feedf95d49f83b35" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/FakerPHP/Faker/zipball/89c6201c74db25fa759ff16e78a4d8f32547770e", - "reference": "89c6201c74db25fa759ff16e78a4d8f32547770e", + "url": "https://api.github.com/repos/FakerPHP/Faker/zipball/271d384d216e5e5c468a6b28feedf95d49f83b35", + "reference": "271d384d216e5e5c468a6b28feedf95d49f83b35", "shasum": "" }, "require": { "php": "^7.1 || ^8.0", - "psr/container": "^1.0", + "psr/container": "^1.0 || ^2.0", "symfony/deprecation-contracts": "^2.2" }, "conflict": { @@ -9632,7 +9677,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-main": "v1.15-dev" + "dev-main": "v1.16-dev" } }, "autoload": { @@ -9657,9 +9702,9 @@ ], "support": { "issues": "https://github.com/FakerPHP/Faker/issues", - "source": "https://github.com/FakerPHP/Faker/tree/v1.15.0" + "source": "https://github.com/FakerPHP/Faker/tree/v1.16.0" }, - "time": "2021-07-06T20:39:40+00:00" + "time": "2021-09-06T14:53:37+00:00" }, { "name": "filp/whoops", @@ -11714,13 +11759,15 @@ "aliases": [], "minimum-stability": "dev", "stability-flags": { - "cubist/cms-back": 20 + "cubist/cms-back": 20, + "fluidbook/tools": 20 }, "prefer-stable": true, "prefer-lowest": false, "platform": { - "php": "^7.3|^8.0", + "php": "^8.0", "ext-json": "*", + "ext-redis": "*", "ext-simplexml": "*", "ext-tidy": "*", "ext-zip": "*" -- 2.39.5