]> _ Git - fluidbook-toolbox.git/commitdiff
wait #5399
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Mon, 26 Jun 2023 16:07:11 +0000 (18:07 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Mon, 26 Jun 2023 16:07:11 +0000 (18:07 +0200)
app/Fluidbook/Compiler/Compiler.php
app/Fluidbook/Compiler/Images.php [new file with mode: 0644]
app/Http/Controllers/Admin/Operations/FluidbookPublication/PreviewOperation.php

index 20b63e288b0b22bf786c69dd58a44451f62804bc..3fb738bd43406e16c87913c0cdc04f7cd0fbf520 100644 (file)
@@ -48,6 +48,7 @@ class Compiler extends Base implements CompilerInterface
     use \Fluidbook\Tools\Compiler\FluidbookCompiler;
     use Favicon;
     use Secure;
+    use Images;
 
     protected static $uaPrefixes = array('-moz-', '-webkit-', '-o-', '-ms-', '');
 
@@ -1820,68 +1821,6 @@ class Compiler extends Base implements CompilerInterface
         return $res;
     }
 
-    protected function writeImages()
-    {
-        set_time_limit(0);
-        switch ($this->fluidbookSettings->mobileVersion) {
-            case 'html5-desktop':
-                $this->backgroundsPrefix = array(true, false);
-                $this->svg = true;
-                break;
-            case 'html5-images':
-                $this->backgroundsPrefix = array(true);
-                $this->svg = false;
-                break;
-            default:
-                $this->backgroundsPrefix = array(false);
-                $this->svg = true;
-                break;
-        }
-
-        $rasterizePages = $this->config->rasterizePages;
-        $this->config->pagesDimensions = [];
-
-        if ($this->fluidbookSettings->mobileNavigationType === 'mobilefirst') {
-            $imdir = 'mf';
-        } else {
-            $imdir = 'html';
-        }
-
-        $thumbs = array();
-        foreach ($this->pages as $page => $infos) {
-            $thisrasterize = in_array($page, $rasterizePages);
-            $thisimagesvg = !$thisrasterize && $this->svg;
-            $thisbackgroundPrefix = $thisrasterize ? [true] : $this->backgroundsPrefix;
-
-            foreach ($this->getResolutions() as $r) {
-                foreach ($thisbackgroundPrefix as $backgroundsPrefix) {
-                    $source = $this->getFluidbook()->getFile($page, $this->imageFormat, $r, $backgroundsPrefix, true, $imdir);
-                    if ($r === $this->maxRes) {
-                        $this->getPageDimension($page);
-                    }
-                    $this->vdir->copy($source, 'data/background/' . $r . '/' . ($backgroundsPrefix ? 't' : 'p') . $page . '.' . $this->imageFormat);
-                }
-            }
-
-            if ($thisimagesvg) {
-                $this->vdir->copy(
-                    $this->getFluidbook()->getFile($page, 'svg', 150, true,
-                        in_array($page, $this->config->vectorPages), 'html')
-                    , 'data/contents/p' . $page . '.svg');
-            }
-
-            $t = $this->getFluidbook()->getThumbFile($page, $this->imageFormat);
-            $this->vdir->copy($t, 'data/thumbnails/p' . $page . '.' . $this->imageFormat);
-            $this->log('Made image page ' . $page);
-        }
-
-
-        $this->_makeCover($this->getFluidbook()->getFile(1, 'jpg', 150, true, true));
-        $this->log('Made cover for apps');
-
-        $this->log('Made images');
-    }
-
 
     /**
      * @param $page
@@ -1910,35 +1849,7 @@ class Compiler extends Base implements CompilerInterface
     }
 
 
-    protected function _makeCover($orig)
-    {
-        $cached = $this->wdir . '/_cover.jpg';
-
-        if (!file_exists($cached) || filemtime($cached) < filemtime($orig)) {
-            $size = Image::getimagesize($orig);
-            $w = $size[0];
-            $h = $size[1];
-
-            $tmp = Files::tempnam() . '.png';
-
-            $c = new CommandLine('convert');
-            $c->setArg(null, resource_path('fluidbookpublication/cover/shade-cover-app.png'));
-            $c->setManualArg('-resize ' . round($w / 3) . 'x' . $h);
-            $c->setArg(null, $tmp);
-            $c->execute();
 
-            $convert = new CommandLine('composite');
-            $cmd = '-compose Multiply ';
-            $cmd .= $tmp . ' ' . $orig . ' ';
-            $cmd .= $cached;
-            $convert->setManualArg($cmd);
-            $convert->execute();
-
-            unlink($tmp);
-        }
-        $this->vdir->copy($cached, 'cover.jpg', true);
-
-    }
 
     protected function _lessBoolean($val)
     {
diff --git a/app/Fluidbook/Compiler/Images.php b/app/Fluidbook/Compiler/Images.php
new file mode 100644 (file)
index 0000000..9340d7e
--- /dev/null
@@ -0,0 +1,104 @@
+<?php
+
+namespace App\Fluidbook\Compiler;
+
+use Cubist\Util\CommandLine;
+use Cubist\Util\Files\Files;
+use Cubist\Util\Graphics\Image;
+
+trait Images
+{
+
+    protected function writeImages()
+    {
+        set_time_limit(0);
+        switch ($this->fluidbookSettings->mobileVersion) {
+            case 'html5-desktop':
+                $this->backgroundsPrefix = array(true, false);
+                $this->svg = true;
+                break;
+            case 'html5-images':
+                $this->backgroundsPrefix = array(true);
+                $this->svg = false;
+                break;
+            default:
+                $this->backgroundsPrefix = array(false);
+                $this->svg = true;
+                break;
+        }
+
+        $rasterizePages = $this->config->rasterizePages;
+        $this->config->pagesDimensions = [];
+
+        if ($this->fluidbookSettings->mobileNavigationType === 'mobilefirst') {
+            $imdir = 'mf';
+        } else {
+            $imdir = 'html';
+        }
+
+        $thumbs = array();
+        foreach ($this->pages as $page => $infos) {
+            $thisrasterize = in_array($page, $rasterizePages);
+            $thisimagesvg = !$thisrasterize && $this->svg;
+            $thisbackgroundPrefix = $thisrasterize ? [true] : $this->backgroundsPrefix;
+
+            foreach ($this->getResolutions() as $r) {
+                foreach ($thisbackgroundPrefix as $backgroundsPrefix) {
+                    $source = $this->getFluidbook()->getFile($page, $this->imageFormat, $r, $backgroundsPrefix, true, $imdir);
+                    if ($r === $this->maxRes) {
+                        $this->getPageDimension($page);
+                    }
+                    $this->vdir->copy($source, 'data/background/' . $r . '/' . ($backgroundsPrefix ? 't' : 'p') . $page . '.' . $this->imageFormat);
+                }
+            }
+
+            if ($thisimagesvg) {
+                $this->vdir->copy(
+                    $this->getFluidbook()->getFile($page, 'svg', 150, true,
+                        in_array($page, $this->config->vectorPages), 'html')
+                    , 'data/contents/p' . $page . '.svg');
+            }
+
+            $t = $this->getFluidbook()->getThumbFile($page, $this->imageFormat);
+            $this->vdir->copy($t, 'data/thumbnails/p' . $page . '.' . $this->imageFormat);
+            $this->log('Made image page ' . $page);
+        }
+
+
+        $this->_makeCover($this->getFluidbook()->getFile(1, 'jpg', 150, true, true));
+        $this->log('Made cover for apps');
+
+        $this->log('Made images');
+    }
+
+    protected function _makeCover($orig)
+    {
+        $cached = $this->wdir . '/_cover.jpg';
+
+        if (!file_exists($cached) || filemtime($cached) < filemtime($orig)) {
+            $size = Image::getimagesize($orig);
+            $w = $size[0];
+            $h = $size[1];
+
+            $tmp = Files::tempnam() . '.png';
+
+            $c = new CommandLine('convert');
+            $c->setArg(null, resource_path('fluidbookpublication/cover/shade-cover-app.png'));
+            $c->setManualArg('-resize ' . round($w / 3) . 'x' . $h);
+            $c->setArg(null, $tmp);
+            $c->execute();
+
+            $convert = new CommandLine('composite');
+            $cmd = '-compose Multiply ';
+            $cmd .= $tmp . ' ' . $orig . ' ';
+            $cmd .= $cached;
+            $convert->setManualArg($cmd);
+            $convert->execute();
+
+            unlink($tmp);
+        }
+        $this->vdir->copy($cached, 'cover.jpg', true);
+
+    }
+
+}
index fa284fec5566b2de893c0f484f607c77d66a0b33..c604d5d080db1f3d5151e64bb77eb99e21755c77 100644 (file)
@@ -8,6 +8,7 @@ use App\Http\Middleware\CheckIfAdmin;
 use App\Models\FluidbookPublication;
 use App\Models\FluidbookTheme;
 use Cubist\Backpack\Http\Controllers\Base\XSendFileController;
+use Cubist\Util\PHP;
 use Illuminate\Support\Facades\Auth;
 use Illuminate\Support\Facades\Route;
 
@@ -15,6 +16,7 @@ use Illuminate\Support\Facades\Route;
 trait PreviewOperation
 {
     use FluidbookPreviewOperation;
+
     protected function setupPreviewRoutes($segment, $routeName, $controller)
     {
         Route::match(['get'], $segment . '/preview/{version}/{id}_{hash}', function ($version, $id, $hash) use ($segment) {
@@ -44,6 +46,7 @@ trait PreviewOperation
 
     protected function _preview($segment, $version, $id, $hash, $time = null, $path = null)
     {
+        PHP::neverStop(false);
         $q = request()->getQueryString();
         if ($q) {
             $q = '?' . $q;
@@ -94,6 +97,8 @@ trait PreviewOperation
      */
     public function loadingCompile($url, $id, $hash)
     {
+        PHP::neverStop(false);
+
         self::_getFluidbookAndTheme($id, $hash, $fluidbook, $theme);
         $res = $this->_loadingCompile($theme, $fluidbook->title, $url);
         return response($res);
@@ -109,6 +114,8 @@ trait PreviewOperation
      */
     public function preview($version, $fluidbook, $theme, $path = 'index.html')
     {
+        PHP::neverStop(false);
+
         $isScorm = $version === 'scorm';
 
         $dest = $fluidbook->getFinalPath($theme, $isScorm);