@@ -59,7 +59,7 @@ |
||
| 59 | 59 | } |
| 60 | 60 | |
| 61 | 61 | if (!is_file($path)) { |
| 62 | - Craft::error('Tried to load an image at ' . $path . ', but the file does not exist.', __METHOD__); |
|
| 62 | + Craft::error('Tried to load an image at '.$path.', but the file does not exist.', __METHOD__); |
|
| 63 | 63 | throw new ImageException(Craft::t('app', 'No file exists at the given path.')); |
| 64 | 64 | } |
| 65 | 65 | |
@@ -187,7 +187,7 @@ discard block |
||
| 187 | 187 | * @inheritdoc |
| 188 | 188 | * @since 1.6.2 |
| 189 | 189 | */ |
| 190 | - public function getContentGqlType(): Type|array |
|
| 190 | + public function getContentGqlType(): Type | array |
|
| 191 | 191 | { |
| 192 | 192 | $typeArray = OptimizedImagesGenerator::generateTypes($this); |
| 193 | 193 | |
@@ -276,7 +276,7 @@ discard block |
||
| 276 | 276 | /** |
| 277 | 277 | * @inheritdoc |
| 278 | 278 | */ |
| 279 | - public function getSettingsHtml(): null|string |
|
| 279 | + public function getSettingsHtml(): null | string |
|
| 280 | 280 | { |
| 281 | 281 | $namespace = Craft::$app->getView()->getNamespace(); |
| 282 | 282 | if (str_contains($namespace, Matrix::class) || str_contains($namespace, SuperTableField::class)) { |
@@ -312,14 +312,14 @@ discard block |
||
| 312 | 312 | $sizesWrapperId = Craft::$app->getView()->namespaceInputId('sizes-wrapper'); |
| 313 | 313 | $view = Craft::$app->getView(); |
| 314 | 314 | $view->registerJs( |
| 315 | - 'document.addEventListener("vite-script-loaded", function (e) {' . |
|
| 316 | - 'if (e.detail.path === "../src/web/assets/src/js/OptimizedImagesField.js") {' . |
|
| 317 | - 'new Craft.OptimizedImagesInput(' . |
|
| 318 | - '"' . $namespacedId . '", ' . |
|
| 319 | - '"' . $namespacePrefix . '",' . |
|
| 320 | - '"' . $sizesWrapperId . '"' . |
|
| 321 | - ');' . |
|
| 322 | - '}' . |
|
| 315 | + 'document.addEventListener("vite-script-loaded", function (e) {'. |
|
| 316 | + 'if (e.detail.path === "../src/web/assets/src/js/OptimizedImagesField.js") {'. |
|
| 317 | + 'new Craft.OptimizedImagesInput('. |
|
| 318 | + '"'.$namespacedId.'", '. |
|
| 319 | + '"'.$namespacePrefix.'",'. |
|
| 320 | + '"'.$sizesWrapperId.'"'. |
|
| 321 | + ');'. |
|
| 322 | + '}'. |
|
| 323 | 323 | '});' |
| 324 | 324 | ); |
| 325 | 325 | |
@@ -387,12 +387,12 @@ discard block |
||
| 387 | 387 | $jsonVars = Json::encode($jsonVars); |
| 388 | 388 | $view = Craft::$app->getView(); |
| 389 | 389 | $view->registerJs( |
| 390 | - 'document.addEventListener("vite-script-loaded", function (e) {' . |
|
| 391 | - 'if (e.detail.path === "../src/web/assets/src/js/OptimizedImagesField.js") {' . |
|
| 392 | - "$('#{$nameSpaceId}-field').ImageOptimizeOptimizedImages(" . |
|
| 393 | - $jsonVars . |
|
| 394 | - ");" . |
|
| 395 | - '}' . |
|
| 390 | + 'document.addEventListener("vite-script-loaded", function (e) {'. |
|
| 391 | + 'if (e.detail.path === "../src/web/assets/src/js/OptimizedImagesField.js") {'. |
|
| 392 | + "$('#{$nameSpaceId}-field').ImageOptimizeOptimizedImages(". |
|
| 393 | + $jsonVars. |
|
| 394 | + ");". |
|
| 395 | + '}'. |
|
| 396 | 396 | '});' |
| 397 | 397 | ); |
| 398 | 398 | |
@@ -41,7 +41,7 @@ |
||
| 41 | 41 | $model->addError( |
| 42 | 42 | $attribute, |
| 43 | 43 | Craft::t('image-optimize', 'Object failed to validate') |
| 44 | - . '-' . $attributeError . ' - ' . $valueError |
|
| 44 | + . '-'.$attributeError.' - '.$valueError |
|
| 45 | 45 | ); |
| 46 | 46 | } |
| 47 | 47 | } |
@@ -119,7 +119,7 @@ discard block |
||
| 119 | 119 | * |
| 120 | 120 | * @return ?ImageTransformInterface The Image Transform |
| 121 | 121 | */ |
| 122 | - public function createImageTransformType(string|array $config): ?ImageTransformInterface |
|
| 122 | + public function createImageTransformType(string | array $config): ?ImageTransformInterface |
|
| 123 | 123 | { |
| 124 | 124 | if (is_string($config)) { |
| 125 | 125 | $config = ['type' => $config]; |
@@ -388,7 +388,7 @@ discard block |
||
| 388 | 388 | . '%'; |
| 389 | 389 | Craft::info($message, __METHOD__); |
| 390 | 390 | if (Craft::$app instanceof ConsoleApplication) { |
| 391 | - echo $message . PHP_EOL; |
|
| 391 | + echo $message.PHP_EOL; |
|
| 392 | 392 | } |
| 393 | 393 | // Create any image variants |
| 394 | 394 | $this->createImageVariants( |
@@ -426,14 +426,14 @@ discard block |
||
| 426 | 426 | */ |
| 427 | 427 | public function saveTransformToTempFile(AssetTransformIndex $index, Image $image): string |
| 428 | 428 | { |
| 429 | - $tempFilename = uniqid(pathinfo($index->filename, PATHINFO_FILENAME), true) . '.' . $index->detectedFormat; |
|
| 430 | - $tempPath = Craft::$app->getPath()->getTempPath() . DIRECTORY_SEPARATOR . $tempFilename; |
|
| 429 | + $tempFilename = uniqid(pathinfo($index->filename, PATHINFO_FILENAME), true).'.'.$index->detectedFormat; |
|
| 430 | + $tempPath = Craft::$app->getPath()->getTempPath().DIRECTORY_SEPARATOR.$tempFilename; |
|
| 431 | 431 | try { |
| 432 | 432 | $image->saveAs($tempPath); |
| 433 | 433 | } catch (ImageException $e) { |
| 434 | - Craft::error('Transformed image save failed: ' . $e->getMessage(), __METHOD__); |
|
| 434 | + Craft::error('Transformed image save failed: '.$e->getMessage(), __METHOD__); |
|
| 435 | 435 | } |
| 436 | - Craft::info('Transformed image saved to: ' . $tempPath, __METHOD__); |
|
| 436 | + Craft::info('Transformed image saved to: '.$tempPath, __METHOD__); |
|
| 437 | 437 | |
| 438 | 438 | return $tempPath; |
| 439 | 439 | } |
@@ -546,7 +546,7 @@ discard block |
||
| 546 | 546 | . '%'; |
| 547 | 547 | Craft::info($message, __METHOD__); |
| 548 | 548 | if (Craft::$app instanceof ConsoleApplication) { |
| 549 | - echo $message . PHP_EOL; |
|
| 549 | + echo $message.PHP_EOL; |
|
| 550 | 550 | } |
| 551 | 551 | // Copy the image variant into place |
| 552 | 552 | $this->copyImageVariantToVolume( |
@@ -644,8 +644,8 @@ discard block |
||
| 644 | 644 | // Handle auto-sharpening scaled down images |
| 645 | 645 | if ($imagineImage !== null && $settings->autoSharpenScaledImages) { |
| 646 | 646 | // See if the image has been scaled >= 50% |
| 647 | - $widthScale = (int)(($image->getWidth() / $asset->getWidth()) * 100); |
|
| 648 | - $heightScale = (int)(($image->getHeight() / $asset->getHeight()) * 100); |
|
| 647 | + $widthScale = (int) (($image->getWidth() / $asset->getWidth()) * 100); |
|
| 648 | + $heightScale = (int) (($image->getHeight() / $asset->getHeight()) * 100); |
|
| 649 | 649 | if (($widthScale >= $settings->sharpenScaledImagePercentage) || ($heightScale >= $settings->sharpenScaledImagePercentage)) { |
| 650 | 650 | $imagineImage->effects() |
| 651 | 651 | ->sharpen(); |
@@ -700,7 +700,7 @@ discard block |
||
| 700 | 700 | . escapeshellarg($tempPath); |
| 701 | 701 | // Execute the command |
| 702 | 702 | $shellOutput = $this->executeShellCommand($cmd); |
| 703 | - Craft::info($cmd . "\n" . $shellOutput, __METHOD__); |
|
| 703 | + Craft::info($cmd."\n".$shellOutput, __METHOD__); |
|
| 704 | 704 | } else { |
| 705 | 705 | Craft::error( |
| 706 | 706 | $thisProcessor['commandPath'] |
@@ -752,7 +752,7 @@ discard block |
||
| 752 | 752 | // Make sure the command exists |
| 753 | 753 | if (is_file($variantCreatorCommand['commandPath'])) { |
| 754 | 754 | // Get the output file for this image variant |
| 755 | - $outputPath .= '.' . $variantCreatorCommand['imageVariantExtension']; |
|
| 755 | + $outputPath .= '.'.$variantCreatorCommand['imageVariantExtension']; |
|
| 756 | 756 | // Set any options for the command |
| 757 | 757 | $commandOptions = ''; |
| 758 | 758 | if (!empty($variantCreatorCommand['commandOptions'])) { |
@@ -787,7 +787,7 @@ discard block |
||
| 787 | 787 | . escapeshellarg($tempPath); |
| 788 | 788 | // Execute the command |
| 789 | 789 | $shellOutput = $this->executeShellCommand($cmd); |
| 790 | - Craft::info($cmd . "\n" . $shellOutput, __METHOD__); |
|
| 790 | + Craft::info($cmd."\n".$shellOutput, __METHOD__); |
|
| 791 | 791 | } else { |
| 792 | 792 | Craft::error( |
| 793 | 793 | $variantCreatorCommand['commandPath'] |
@@ -832,17 +832,17 @@ discard block |
||
| 832 | 832 | } catch (InvalidConfigException $invalidConfigException) { |
| 833 | 833 | $fs = null; |
| 834 | 834 | Craft::error( |
| 835 | - 'Asset file system error: ' . $invalidConfigException->getMessage(), |
|
| 835 | + 'Asset file system error: '.$invalidConfigException->getMessage(), |
|
| 836 | 836 | __METHOD__ |
| 837 | 837 | ); |
| 838 | 838 | } |
| 839 | 839 | |
| 840 | - $variantPath = $uri . '.' . $variantCreatorCommand['imageVariantExtension']; |
|
| 840 | + $variantPath = $uri.'.'.$variantCreatorCommand['imageVariantExtension']; |
|
| 841 | 841 | |
| 842 | 842 | // Delete the variant file in case it is stale |
| 843 | 843 | $fs->deleteFile($variantPath); |
| 844 | 844 | Craft::info( |
| 845 | - 'Deleted variant: ' . $variantPath, |
|
| 845 | + 'Deleted variant: '.$variantPath, |
|
| 846 | 846 | __METHOD__ |
| 847 | 847 | ); |
| 848 | 848 | } |
@@ -875,17 +875,17 @@ discard block |
||
| 875 | 875 | } catch (InvalidConfigException $e) { |
| 876 | 876 | $fs = null; |
| 877 | 877 | Craft::error( |
| 878 | - 'Asset volume error: ' . $e->getMessage(), |
|
| 878 | + 'Asset volume error: '.$e->getMessage(), |
|
| 879 | 879 | __METHOD__ |
| 880 | 880 | ); |
| 881 | 881 | } |
| 882 | 882 | |
| 883 | - $variantPath = $uri . '.' . $variantCreatorCommand['imageVariantExtension']; |
|
| 883 | + $variantPath = $uri.'.'.$variantCreatorCommand['imageVariantExtension']; |
|
| 884 | 884 | |
| 885 | 885 | // Delete the variant file in case it is stale |
| 886 | 886 | $fs->deleteFile($variantPath); |
| 887 | 887 | Craft::info( |
| 888 | - 'Variant output path: ' . $outputPath . ' - Variant path: ' . $variantPath, |
|
| 888 | + 'Variant output path: '.$outputPath.' - Variant path: '.$variantPath, |
|
| 889 | 889 | __METHOD__ |
| 890 | 890 | ); |
| 891 | 891 | clearstatcache(true, $outputPath); |
@@ -913,9 +913,9 @@ discard block |
||
| 913 | 913 | protected function swapPathExtension(string $path, string $extension): string |
| 914 | 914 | { |
| 915 | 915 | $pathParts = pathinfo($path); |
| 916 | - $newPath = $pathParts['filename'] . '.' . $extension; |
|
| 916 | + $newPath = $pathParts['filename'].'.'.$extension; |
|
| 917 | 917 | if (!empty($pathParts['dirname']) && $pathParts['dirname'] !== '.') { |
| 918 | - $newPath = $pathParts['dirname'] . DIRECTORY_SEPARATOR . $newPath; |
|
| 918 | + $newPath = $pathParts['dirname'].DIRECTORY_SEPARATOR.$newPath; |
|
| 919 | 919 | $newPath = preg_replace('#/+#', '/', $newPath); |
| 920 | 920 | } |
| 921 | 921 | |
@@ -547,7 +547,7 @@ discard block |
||
| 547 | 547 | return $this->defaultPlaceholderImage(); |
| 548 | 548 | } |
| 549 | 549 | |
| 550 | - return Template::raw($header . rawurlencode($content)); |
|
| 550 | + return Template::raw($header.rawurlencode($content)); |
|
| 551 | 551 | } |
| 552 | 552 | |
| 553 | 553 | /** |
@@ -625,7 +625,7 @@ discard block |
||
| 625 | 625 | return $this->defaultPlaceholderImage(); |
| 626 | 626 | } |
| 627 | 627 | |
| 628 | - return Template::raw($header . $content); |
|
| 628 | + return Template::raw($header.$content); |
|
| 629 | 629 | } |
| 630 | 630 | |
| 631 | 631 | /** |
@@ -753,16 +753,16 @@ discard block |
||
| 753 | 753 | foreach ($array as $key => $value) { |
| 754 | 754 | if ($dpr) { |
| 755 | 755 | $descriptor = '1x'; |
| 756 | - if (!empty($array[(int)$key / 2])) { |
|
| 756 | + if (!empty($array[(int) $key / 2])) { |
|
| 757 | 757 | $descriptor = '2x'; |
| 758 | 758 | } |
| 759 | - if (!empty($array[(int)$key / 3])) { |
|
| 759 | + if (!empty($array[(int) $key / 3])) { |
|
| 760 | 760 | $descriptor = '3x'; |
| 761 | 761 | } |
| 762 | 762 | } else { |
| 763 | - $descriptor = $key . 'w'; |
|
| 763 | + $descriptor = $key.'w'; |
|
| 764 | 764 | } |
| 765 | - $srcset .= $value . ' ' . $descriptor . ', '; |
|
| 765 | + $srcset .= $value.' '.$descriptor.', '; |
|
| 766 | 766 | } |
| 767 | 767 | |
| 768 | 768 | return rtrim($srcset, ', '); |
@@ -796,13 +796,13 @@ discard block |
||
| 796 | 796 | { |
| 797 | 797 | // Set the class and loading attributes |
| 798 | 798 | if (isset($attrs['class'])) { |
| 799 | - $attrs['class'] = trim($attrs['class'] . ' lazyload'); |
|
| 799 | + $attrs['class'] = trim($attrs['class'].' lazyload'); |
|
| 800 | 800 | } |
| 801 | 801 | // Set the style on this element to be the placeholder image as the background-image |
| 802 | 802 | if (isset($attrs['style']) && !empty($attrs['src'])) { |
| 803 | 803 | $attrs['style'] = trim( |
| 804 | - $attrs['style'] . |
|
| 805 | - 'background-image:url(' . $this->getLazyLoadSrc($placeHolder) . '); background-size: cover;' |
|
| 804 | + $attrs['style']. |
|
| 805 | + 'background-image:url('.$this->getLazyLoadSrc($placeHolder).'); background-size: cover;' |
|
| 806 | 806 | ); |
| 807 | 807 | } |
| 808 | 808 | // Handle attributes that lazy and lazySizesFallback have in common |
@@ -45,7 +45,7 @@ discard block |
||
| 45 | 45 | * |
| 46 | 46 | * @return string|null |
| 47 | 47 | */ |
| 48 | - public function getTransformUrl(Asset $asset, CraftImageTransformModel|string|array|null $transform): ?string; |
|
| 48 | + public function getTransformUrl(Asset $asset, CraftImageTransformModel | string | array | null $transform): ?string; |
|
| 49 | 49 | |
| 50 | 50 | /** |
| 51 | 51 | * Return a URL to the webp version of the transformed image |
@@ -56,7 +56,7 @@ discard block |
||
| 56 | 56 | * |
| 57 | 57 | * @return ?string |
| 58 | 58 | */ |
| 59 | - public function getWebPUrl(string $url, Asset $asset, CraftImageTransformModel|string|array|null $transform): ?string; |
|
| 59 | + public function getWebPUrl(string $url, Asset $asset, CraftImageTransformModel | string | array | null $transform): ?string; |
|
| 60 | 60 | |
| 61 | 61 | /** |
| 62 | 62 | * Return the URL that should be used to purge the Asset |
@@ -57,7 +57,7 @@ discard block |
||
| 57 | 57 | /** |
| 58 | 58 | * @inheritDoc |
| 59 | 59 | */ |
| 60 | - public function getTransformUrl(Asset $asset, CraftImageTransformModel|string|array|null $transform): ?string |
|
| 60 | + public function getTransformUrl(Asset $asset, CraftImageTransformModel | string | array | null $transform): ?string |
|
| 61 | 61 | { |
| 62 | 62 | // Generate the URLs to the optimized images |
| 63 | 63 | $oldValue = Craft::$app->getConfig()->getGeneral()->generateTransformsBeforePageLoad; |
@@ -74,7 +74,7 @@ discard block |
||
| 74 | 74 | /** |
| 75 | 75 | * @inheritDoc |
| 76 | 76 | */ |
| 77 | - public function getWebPUrl(string $url, Asset $asset, CraftImageTransformModel|string|array|null $transform): ?string |
|
| 77 | + public function getWebPUrl(string $url, Asset $asset, CraftImageTransformModel | string | array | null $transform): ?string |
|
| 78 | 78 | { |
| 79 | 79 | return $this->appendExtension($url, '.webp'); |
| 80 | 80 | } |
@@ -37,12 +37,12 @@ discard block |
||
| 37 | 37 | } |
| 38 | 38 | |
| 39 | 39 | if (strlen($htmlCode) === 3) { |
| 40 | - $htmlCode = $htmlCode[0] . $htmlCode[0] . $htmlCode[1] . $htmlCode[1] . $htmlCode[2] . $htmlCode[2]; |
|
| 40 | + $htmlCode = $htmlCode[0].$htmlCode[0].$htmlCode[1].$htmlCode[1].$htmlCode[2].$htmlCode[2]; |
|
| 41 | 41 | } |
| 42 | 42 | |
| 43 | - $r = hexdec($htmlCode[0] . $htmlCode[1]); |
|
| 44 | - $g = hexdec($htmlCode[2] . $htmlCode[3]); |
|
| 45 | - $b = hexdec($htmlCode[4] . $htmlCode[5]); |
|
| 43 | + $r = hexdec($htmlCode[0].$htmlCode[1]); |
|
| 44 | + $g = hexdec($htmlCode[2].$htmlCode[3]); |
|
| 45 | + $b = hexdec($htmlCode[4].$htmlCode[5]); |
|
| 46 | 46 | |
| 47 | 47 | return ['r' => $r, 'g' => $g, 'b' => $b]; |
| 48 | 48 | } |
@@ -56,9 +56,9 @@ discard block |
||
| 56 | 56 | */ |
| 57 | 57 | public static function RGBToHSL(array $rgb): array |
| 58 | 58 | { |
| 59 | - $r = ((float)$rgb['r']) / 255.0; |
|
| 60 | - $g = ((float)$rgb['g']) / 255.0; |
|
| 61 | - $b = ((float)$rgb['b']) / 255.0; |
|
| 59 | + $r = ((float) $rgb['r']) / 255.0; |
|
| 60 | + $g = ((float) $rgb['g']) / 255.0; |
|
| 61 | + $b = ((float) $rgb['b']) / 255.0; |
|
| 62 | 62 | |
| 63 | 63 | $maxC = max($r, $g, $b); |
| 64 | 64 | $minC = min($r, $g, $b); |
@@ -86,9 +86,9 @@ discard block |
||
| 86 | 86 | $h /= 6.0; |
| 87 | 87 | } |
| 88 | 88 | |
| 89 | - $h = (int)round(360.0 * $h); |
|
| 90 | - $s = (int)round(100.0 * $s); |
|
| 91 | - $l = (int)round(100.0 * $l); |
|
| 89 | + $h = (int) round(360.0 * $h); |
|
| 90 | + $s = (int) round(100.0 * $s); |
|
| 91 | + $l = (int) round(100.0 * $l); |
|
| 92 | 92 | |
| 93 | 93 | return ['h' => $h, 's' => $s, 'l' => $l]; |
| 94 | 94 | } |
@@ -41,8 +41,8 @@ discard block |
||
| 41 | 41 | // so we can't extract it from the passed in $config |
| 42 | 42 | $majorVersion = '4'; |
| 43 | 43 | // Dev server container name & port are based on the major version of this plugin |
| 44 | - $devPort = 3000 + (int)$majorVersion; |
|
| 45 | - $versionName = 'v' . $majorVersion; |
|
| 44 | + $devPort = 3000 + (int) $majorVersion; |
|
| 45 | + $versionName = 'v'.$majorVersion; |
|
| 46 | 46 | return [ |
| 47 | 47 | 'components' => [ |
| 48 | 48 | 'optimize' => OptimizeService::class, |
@@ -53,8 +53,8 @@ discard block |
||
| 53 | 53 | 'assetClass' => ImageOptimizeAsset::class, |
| 54 | 54 | 'checkDevServer' => true, |
| 55 | 55 | 'class' => VitePluginService::class, |
| 56 | - 'devServerInternal' => 'http://craft-imageoptimize-' . $versionName . '-buildchain-dev:' . $devPort, |
|
| 57 | - 'devServerPublic' => 'http://localhost:' . $devPort, |
|
| 56 | + 'devServerInternal' => 'http://craft-imageoptimize-'.$versionName.'-buildchain-dev:'.$devPort, |
|
| 57 | + 'devServerPublic' => 'http://localhost:'.$devPort, |
|
| 58 | 58 | 'errorEntry' => 'src/js/ImageOptimize.js', |
| 59 | 59 | 'useDevServer' => true, |
| 60 | 60 | ], |