]> _ Git - cubist_util.git/commitdiff
wip #5769 @1
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Thu, 2 Mar 2023 21:29:18 +0000 (22:29 +0100)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Thu, 2 Mar 2023 21:29:18 +0000 (22:29 +0100)
composer.json
composer.lock
src/Graphics/Image.php
src/Graphics/Resizer.php

index 1354163b96fe1bc527e7e966336bd8aef6f23fe0..2cc5b85c1533cb2f5b58cf54498c10bae7f70db3 100644 (file)
@@ -32,6 +32,7 @@
     "ext-sodium": "*",
     "laravel/framework": "~5.8|^6.0|^7.0|^8.0",
     "cubist/net": "dev-master",
-    "dpb587/microdata-dom": "dev-master"
+    "dpb587/microdata-dom": "dev-master",
+    "cubist/pdf": "dev-master"
   }
 }
index d81c605d9b57fb559e0a8531d85dfa6c466a39e1..278a4447f7eb2a6a1f0727e5b40d2484f4e7c7d7 100644 (file)
@@ -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": "93cb873c086aa9bc665faf4289e64fce",
+    "content-hash": "f353439092103527932eadf9bc1faa09",
     "packages": [
         {
             "name": "brick/math",
             "description": "net cubist composer package",
             "time": "2023-01-27T14:43:25+00:00"
         },
+        {
+            "name": "cubist/pdf",
+            "version": "dev-master",
+            "source": {
+                "type": "git",
+                "url": "git://git.cubedesigners.com/cubist_pdf.git",
+                "reference": "97b5e96140945c11230ab5dc48219e30d8a6f3c2"
+            },
+            "dist": {
+                "type": "tar",
+                "url": "https://composer.cubedesigners.com/dist/cubist/pdf/cubist-pdf-dev-master-426fa1.tar",
+                "reference": "97b5e96140945c11230ab5dc48219e30d8a6f3c2",
+                "shasum": "2313cfd88752a2ef63f0a94ef27bf636c488ff1c"
+            },
+            "require": {
+                "cubist/util": "dev-master",
+                "ext-dom": "*",
+                "ext-json": "*",
+                "ext-libxml": "*",
+                "laravel/framework": "~5.8|^6.0|^7.0|^8.0",
+                "php": ">=7.4"
+            },
+            "default-branch": true,
+            "type": "library",
+            "extra": {
+                "laravel": {
+                    "providers": []
+                }
+            },
+            "autoload": {
+                "psr-4": {
+                    "Cubist\\PDF\\": "src"
+                }
+            },
+            "license": [
+                "proprietary"
+            ],
+            "authors": [
+                {
+                    "name": "Vincent Vanwaelscappel",
+                    "email": "vincent@cubedesigners.com"
+                }
+            ],
+            "description": "PDF",
+            "keywords": [
+                "cubist",
+                "pdf"
+            ],
+            "time": "2023-03-02T16:43:11+00:00"
+        },
         {
             "name": "dflydev/dot-access-data",
             "version": "dev-main",
     "minimum-stability": "dev",
     "stability-flags": {
         "cubist/net": 20,
-        "dpb587/microdata-dom": 20
+        "dpb587/microdata-dom": 20,
+        "cubist/pdf": 20
     },
     "prefer-stable": false,
     "prefer-lowest": false,
index 25504049971344d2dd09c02fb5e017b97557f24c..404655719b3372a491014df7602676a1ecad8ded 100644 (file)
@@ -2,6 +2,7 @@
 
 namespace Cubist\Util\Graphics;
 
+use Cubist\PDF\PDFTools;
 use Cubist\Util\Animations\OAMAnimation;
 use Cubist\Util\Animations\ZipAnimation;
 use Cubist\Util\Files\Files;
@@ -23,13 +24,16 @@ class Image
             throw new \Exception('File ' . $path . ' does not exist');
         }
 
-        $allowedExtensions = ['svg', 'oam', 'zip', 'jpeg', 'jpg', 'gif', 'png', 'webm'];
+        $allowedExtensions = ['svg', 'oam', 'zip', 'jpeg', 'jpg', 'gif', 'png', 'webm', 'pdf'];
 
         $ext = Files::getExtension($path);
         if (!in_array($ext, $allowedExtensions)) {
             throw new \Exception('File ' . $path . ' is not a valid image');
         }
-        if ($ext === 'svg') {
+        if ($ext === 'pdf') {
+            $i = PDFTools::infos($path);
+            $res = $i['infos']['size'];
+        } else if ($ext === 'svg') {
             $svg = simplexml_load_string(file_get_contents($path));
             $attr = $svg->attributes();
             if (!isset($attr['width']) || !isset($attr['height'])) {
index 44981bd726d22ad704ac6fc06828fa4b1a998cec..e929bbf5bd959cfe566d9a3477ff3cf778a17dc0 100644 (file)
@@ -178,6 +178,33 @@ class Resizer
         return $color;
     }
 
+    public static function keepRatio($naturalWidth, $naturalHeight, $forcedWidth = null, $forcedHeight = null, $contains = true)
+    {
+        $w = $naturalWidth;
+        $h = $naturalHeight;
+        if (!$forcedHeight && !$forcedWidth) {
+            return [$w, $h];
+        }
+
+        $ratio = $naturalWidth / $naturalHeight;
+        if (!$forcedWidth) {
+            $forcedWidth = $naturalWidth;
+        }
+        if (!$forcedHeight) {
+            $forcedHeight = $naturalHeight;
+        }
+        $s1 = $forcedWidth / $naturalWidth;
+        $s2 = $forcedHeight / $naturalHeight;
+        if ($contains) {
+            $scale = min($s1, $s2);
+        } else {
+            $scale = max($s1, $s2);
+        }
+        $w = $naturalWidth * $scale;
+        $h = $naturalHeight * $scale;
+        return [$w, $h];
+    }
+
 }