@@ -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 | |
@@ -69,7 +69,7 @@ discard block |
||
| 69 | 69 | . "style='background:$color' " |
| 70 | 70 | . "/>"; |
| 71 | 71 | |
| 72 | - return $header . ImageOptimize::$plugin->optimizedImages->encodeOptimizedSVGDataUri($content); |
|
| 72 | + return $header.ImageOptimize::$plugin->optimizedImages->encodeOptimizedSVGDataUri($content); |
|
| 73 | 73 | } |
| 74 | 74 | |
| 75 | 75 | /** |
@@ -90,7 +90,7 @@ discard block |
||
| 90 | 90 | ); |
| 91 | 91 | $result = ''; |
| 92 | 92 | $width = self::PLACEHOLDER_WIDTH; |
| 93 | - $height = (int)($width / $aspectRatio); |
|
| 93 | + $height = (int) ($width / $aspectRatio); |
|
| 94 | 94 | $placeholderPath = $this->createImageFromPath($tempPath, $width, $height, self::PLACEHOLDER_QUALITY, $position); |
| 95 | 95 | if (!empty($placeholderPath)) { |
| 96 | 96 | $result = base64_encode(file_get_contents($placeholderPath)); |
@@ -112,7 +112,7 @@ discard block |
||
| 112 | 112 | { |
| 113 | 113 | Craft::beginProfile('generateColorPalette', __METHOD__); |
| 114 | 114 | Craft::info( |
| 115 | - 'Generating color palette for: ' . $tempPath, |
|
| 115 | + 'Generating color palette for: '.$tempPath, |
|
| 116 | 116 | __METHOD__ |
| 117 | 117 | ); |
| 118 | 118 | $colorPalette = []; |
@@ -158,7 +158,7 @@ discard block |
||
| 158 | 158 | $lightness /= $colorCount; |
| 159 | 159 | } |
| 160 | 160 | |
| 161 | - return $lightness === null ? $lightness : (int)$lightness; |
|
| 161 | + return $lightness === null ? $lightness : (int) $lightness; |
|
| 162 | 162 | } |
| 163 | 163 | |
| 164 | 164 | /** |
@@ -224,7 +224,7 @@ discard block |
||
| 224 | 224 | __METHOD__ |
| 225 | 225 | ); |
| 226 | 226 | $width = self::TEMP_PLACEHOLDER_WIDTH; |
| 227 | - $height = (int)($width / $aspectRatio); |
|
| 227 | + $height = (int) ($width / $aspectRatio); |
|
| 228 | 228 | $tempPath = $this->createImageFromAsset($asset, $width, $height, self::TEMP_PLACEHOLDER_QUALITY, $position); |
| 229 | 229 | Craft::endProfile('createTempPlaceholderImage', __METHOD__); |
| 230 | 230 | |
@@ -280,7 +280,7 @@ discard block |
||
| 280 | 280 | } |
| 281 | 281 | } catch (Throwable $e) { |
| 282 | 282 | Craft::error( |
| 283 | - 'Error creating temporary image: ' . $e->getMessage(), |
|
| 283 | + 'Error creating temporary image: '.$e->getMessage(), |
|
| 284 | 284 | __METHOD__ |
| 285 | 285 | ); |
| 286 | 286 | |
@@ -303,14 +303,14 @@ discard block |
||
| 303 | 303 | } |
| 304 | 304 | |
| 305 | 305 | // Save the image out to a temp file, then return its contents |
| 306 | - $tempFilename = uniqid(pathinfo($pathParts['filename'], PATHINFO_FILENAME), true) . '.' . 'jpg'; |
|
| 307 | - $tempPath = Craft::$app->getPath()->getTempPath() . DIRECTORY_SEPARATOR . $tempFilename; |
|
| 306 | + $tempFilename = uniqid(pathinfo($pathParts['filename'], PATHINFO_FILENAME), true).'.'.'jpg'; |
|
| 307 | + $tempPath = Craft::$app->getPath()->getTempPath().DIRECTORY_SEPARATOR.$tempFilename; |
|
| 308 | 308 | clearstatcache(true, $tempPath); |
| 309 | 309 | try { |
| 310 | 310 | $image->saveAs($tempPath); |
| 311 | 311 | } catch (Throwable $e) { |
| 312 | 312 | Craft::error( |
| 313 | - 'Error saving temporary image: ' . $e->getMessage(), |
|
| 313 | + 'Error saving temporary image: '.$e->getMessage(), |
|
| 314 | 314 | __METHOD__ |
| 315 | 315 | ); |
| 316 | 316 | } |
@@ -104,7 +104,7 @@ discard block |
||
| 104 | 104 | // Only try the transform if it's possible |
| 105 | 105 | if (Image::canManipulateAsImage($finalFormat) |
| 106 | 106 | && Image::canManipulateAsImage($asset->getExtension()) |
| 107 | - && (int)$asset->height > 0) { |
|
| 107 | + && (int) $asset->height > 0) { |
|
| 108 | 108 | // Create the transform based on the variant |
| 109 | 109 | /** @var AssetTransform $transform */ |
| 110 | 110 | list($transform, $aspectRatio) = $this->getTransformFromVariant($asset, $variant, $retinaSize); |
@@ -116,16 +116,16 @@ discard block |
||
| 116 | 116 | $index->fileExists = false; |
| 117 | 117 | $transforms->storeTransformIndexData($index); |
| 118 | 118 | $volume = $asset->getVolume(); |
| 119 | - $transformPath = $asset->folderPath . $transforms->getTransformSubpath($asset, $index); |
|
| 119 | + $transformPath = $asset->folderPath.$transforms->getTransformSubpath($asset, $index); |
|
| 120 | 120 | try { |
| 121 | 121 | $volume->deleteFile($transformPath); |
| 122 | 122 | } catch (Throwable $exception) { |
| 123 | 123 | } |
| 124 | 124 | } catch (Throwable $e) { |
| 125 | - $msg = 'Failed to update transform: ' . $e->getMessage(); |
|
| 125 | + $msg = 'Failed to update transform: '.$e->getMessage(); |
|
| 126 | 126 | Craft::error($msg, __METHOD__); |
| 127 | 127 | if (Craft::$app instanceof ConsoleApplication) { |
| 128 | - echo $msg . PHP_EOL; |
|
| 128 | + echo $msg.PHP_EOL; |
|
| 129 | 129 | } |
| 130 | 130 | // Add the error message to the stickyErrors for the model |
| 131 | 131 | $model->stickyErrors[] = $msg; |
@@ -139,16 +139,16 @@ discard block |
||
| 139 | 139 | } |
| 140 | 140 | } else { |
| 141 | 141 | $canManipulate = Image::canManipulateAsImage($asset->getExtension()); |
| 142 | - $msg = 'Could not create transform for: ' . $asset->title |
|
| 143 | - . ' - Final format: ' . $finalFormat |
|
| 144 | - . ' - Element extension: ' . $asset->getExtension() |
|
| 145 | - . ' - canManipulateAsImage: ' . $canManipulate; |
|
| 142 | + $msg = 'Could not create transform for: '.$asset->title |
|
| 143 | + . ' - Final format: '.$finalFormat |
|
| 144 | + . ' - Element extension: '.$asset->getExtension() |
|
| 145 | + . ' - canManipulateAsImage: '.$canManipulate; |
|
| 146 | 146 | Craft::error( |
| 147 | 147 | $msg, |
| 148 | 148 | __METHOD__ |
| 149 | 149 | ); |
| 150 | 150 | if (Craft::$app instanceof ConsoleApplication) { |
| 151 | - echo $msg . PHP_EOL; |
|
| 151 | + echo $msg.PHP_EOL; |
|
| 152 | 152 | } |
| 153 | 153 | if ($canManipulate) { |
| 154 | 154 | // Add the error message to the stickyErrors for the model |
@@ -162,7 +162,7 @@ discard block |
||
| 162 | 162 | if (empty($model->optimizedImageUrls)) { |
| 163 | 163 | $finalFormat = $asset->getExtension(); |
| 164 | 164 | if (Image::canManipulateAsImage($finalFormat) |
| 165 | - && (int)$asset->height > 0) { |
|
| 165 | + && (int) $asset->height > 0) { |
|
| 166 | 166 | $variant = [ |
| 167 | 167 | 'width' => $asset->width, |
| 168 | 168 | 'useAspectRatio' => false, |
@@ -175,10 +175,10 @@ discard block |
||
| 175 | 175 | $this->addVariantImageToModel($asset, $model, $transform, $variant, $aspectRatio); |
| 176 | 176 | } else { |
| 177 | 177 | $canManipulate = Image::canManipulateAsImage($asset->getExtension()); |
| 178 | - $msg = 'Could not create transform for: ' . $asset->title |
|
| 179 | - . ' - Final format: ' . $finalFormat |
|
| 180 | - . ' - Element extension: ' . $asset->getExtension() |
|
| 181 | - . ' - canManipulateAsImage: ' . $canManipulate; |
|
| 178 | + $msg = 'Could not create transform for: '.$asset->title |
|
| 179 | + . ' - Final format: '.$finalFormat |
|
| 180 | + . ' - Element extension: '.$asset->getExtension() |
|
| 181 | + . ' - canManipulateAsImage: '.$canManipulate; |
|
| 182 | 182 | Craft::error( |
| 183 | 183 | $msg, |
| 184 | 184 | __METHOD__ |
@@ -217,7 +217,7 @@ discard block |
||
| 217 | 217 | $folder = $asset->getFolder(); |
| 218 | 218 | while ($folder !== null && !$createVariants) { |
| 219 | 219 | if ($folder->uid === $subfolder || $folder->name === $subfolder) { |
| 220 | - Craft::info('Matched subfolder uid: ' . print_r($subfolder, true), __METHOD__); |
|
| 220 | + Craft::info('Matched subfolder uid: '.print_r($subfolder, true), __METHOD__); |
|
| 221 | 221 | $createVariants = true; |
| 222 | 222 | } else { |
| 223 | 223 | $folder = $folder->getParent(); |
@@ -277,7 +277,7 @@ discard block |
||
| 277 | 277 | if ($field->handle !== null) { |
| 278 | 278 | $asset->setFieldValue($field->handle, $field->serializeValue($model)); |
| 279 | 279 | $table = $asset->getContentTable(); |
| 280 | - $column = $asset->getFieldColumnPrefix() . $field->handle; |
|
| 280 | + $column = $asset->getFieldColumnPrefix().$field->handle; |
|
| 281 | 281 | // Special-case for Craft 3.7 or later, with the addition of a suffix to the Field content column name |
| 282 | 282 | // ref: https://github.com/craftcms/cms/issues/6922 |
| 283 | 283 | if (ImageOptimize::$craft37) { |
@@ -344,7 +344,7 @@ discard block |
||
| 344 | 344 | } catch (SiteNotFoundException $e) { |
| 345 | 345 | $siteId = 0; |
| 346 | 346 | Craft::error( |
| 347 | - 'Failed to get primary site: ' . $e->getMessage(), |
|
| 347 | + 'Failed to get primary site: '.$e->getMessage(), |
|
| 348 | 348 | __METHOD__ |
| 349 | 349 | ); |
| 350 | 350 | } |
@@ -450,7 +450,7 @@ discard block |
||
| 450 | 450 | { |
| 451 | 451 | Craft::beginProfile('generatePlaceholders', __METHOD__); |
| 452 | 452 | Craft::info( |
| 453 | - 'generatePlaceholders for: ' . print_r($model, true), |
|
| 453 | + 'generatePlaceholders for: '.print_r($model, true), |
|
| 454 | 454 | __METHOD__ |
| 455 | 455 | ); |
| 456 | 456 | /** @var Settings $settings */ |
@@ -511,20 +511,20 @@ discard block |
||
| 511 | 511 | } |
| 512 | 512 | $useAspectRatio = $variant['useAspectRatio'] ?? false; |
| 513 | 513 | if ($useAspectRatio) { |
| 514 | - $aspectRatio = (float)$variant['aspectRatioX'] / (float)$variant['aspectRatioY']; |
|
| 514 | + $aspectRatio = (float) $variant['aspectRatioX'] / (float) $variant['aspectRatioY']; |
|
| 515 | 515 | } else { |
| 516 | - $aspectRatio = (float)$asset->width / (float)$asset->height; |
|
| 516 | + $aspectRatio = (float) $asset->width / (float) $asset->height; |
|
| 517 | 517 | } |
| 518 | - $width = (int)$variant['width'] * (int)$retinaSize; |
|
| 518 | + $width = (int) $variant['width'] * (int) $retinaSize; |
|
| 519 | 519 | $transform->width = $width; |
| 520 | - $transform->height = (int)($width / $aspectRatio); |
|
| 520 | + $transform->height = (int) ($width / $aspectRatio); |
|
| 521 | 521 | // Image quality |
| 522 | - $quality = (int)($variant['quality'] ?? null); |
|
| 522 | + $quality = (int) ($variant['quality'] ?? null); |
|
| 523 | 523 | if (empty($quality)) { |
| 524 | 524 | $quality = null; |
| 525 | 525 | } |
| 526 | 526 | if ($quality !== null && $settings->lowerQualityRetinaImageVariants && $retinaSize != '1') { |
| 527 | - $quality = (int)($quality * (1.5 / (int)$retinaSize)); |
|
| 527 | + $quality = (int) ($quality * (1.5 / (int) $retinaSize)); |
|
| 528 | 528 | } |
| 529 | 529 | $transform->quality = $quality; |
| 530 | 530 | // Interlaced (progressive JPEGs or interlaced PNGs) |
@@ -551,7 +551,7 @@ discard block |
||
| 551 | 551 | $transform |
| 552 | 552 | ); |
| 553 | 553 | Craft::info( |
| 554 | - 'URL created: ' . print_r($url, true), |
|
| 554 | + 'URL created: '.print_r($url, true), |
|
| 555 | 555 | __METHOD__ |
| 556 | 556 | ); |
| 557 | 557 | // Update the model |
@@ -579,7 +579,7 @@ discard block |
||
| 579 | 579 | $this->generatePlaceholders($asset, $model, $aspectRatio); |
| 580 | 580 | } |
| 581 | 581 | Craft::info( |
| 582 | - 'Created transforms for variant: ' . print_r($variant, true), |
|
| 582 | + 'Created transforms for variant: '.print_r($variant, true), |
|
| 583 | 583 | __METHOD__ |
| 584 | 584 | ); |
| 585 | 585 | } |
@@ -112,7 +112,7 @@ discard block |
||
| 112 | 112 | if (ImageOptimize::$craft31) { |
| 113 | 113 | $subfolder = Craft::parseEnv($subfolder); |
| 114 | 114 | } |
| 115 | - return rtrim($subfolder, '/') . '/' . $assetPath; |
|
| 115 | + return rtrim($subfolder, '/').'/'.$assetPath; |
|
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | return $assetPath; |
@@ -148,14 +148,14 @@ discard block |
||
| 148 | 148 | { |
| 149 | 149 | $path = $this->decomposeUrl($pathOrUrl); |
| 150 | 150 | $path_parts = pathinfo($path['path']); |
| 151 | - $new_path = ($path_parts['filename']) . '.' . ($path_parts['extension'] ?? '') . $extension; |
|
| 151 | + $new_path = ($path_parts['filename']).'.'.($path_parts['extension'] ?? '').$extension; |
|
| 152 | 152 | if (!empty($path_parts['dirname']) && $path_parts['dirname'] !== '.') { |
| 153 | 153 | $dirname = $path_parts['dirname']; |
| 154 | 154 | $dirname = $dirname === '/' ? '' : $dirname; |
| 155 | - $new_path = $dirname . DIRECTORY_SEPARATOR . $new_path; |
|
| 155 | + $new_path = $dirname.DIRECTORY_SEPARATOR.$new_path; |
|
| 156 | 156 | $new_path = preg_replace('/([^:])(\/{2,})/', '$1/', $new_path); |
| 157 | 157 | } |
| 158 | - $output = $path['prefix'] . $new_path . $path['suffix']; |
|
| 158 | + $output = $path['prefix'].$new_path.$path['suffix']; |
|
| 159 | 159 | |
| 160 | 160 | return $output; |
| 161 | 161 | } |
@@ -176,14 +176,14 @@ discard block |
||
| 176 | 176 | |
| 177 | 177 | if (filter_var($pathOrUrl, FILTER_VALIDATE_URL)) { |
| 178 | 178 | $url_parts = parse_url($pathOrUrl); |
| 179 | - $result['prefix'] = $url_parts['scheme'] . '://' . $url_parts['host']; |
|
| 179 | + $result['prefix'] = $url_parts['scheme'].'://'.$url_parts['host']; |
|
| 180 | 180 | if (!empty($url_parts['port'])) { |
| 181 | - $result['prefix'] .= ':' . $url_parts['port']; |
|
| 181 | + $result['prefix'] .= ':'.$url_parts['port']; |
|
| 182 | 182 | } |
| 183 | 183 | $result['path'] = $url_parts['path']; |
| 184 | 184 | $result['suffix'] = ''; |
| 185 | - $result['suffix'] .= empty($url_parts['query']) ? '' : '?' . $url_parts['query']; |
|
| 186 | - $result['suffix'] .= empty($url_parts['fragment']) ? '' : '#' . $url_parts['fragment']; |
|
| 185 | + $result['suffix'] .= empty($url_parts['query']) ? '' : '?'.$url_parts['query']; |
|
| 186 | + $result['suffix'] .= empty($url_parts['fragment']) ? '' : '#'.$url_parts['fragment']; |
|
| 187 | 187 | } else { |
| 188 | 188 | $result['prefix'] = ''; |
| 189 | 189 | $result['path'] = $pathOrUrl; |
@@ -279,6 +279,6 @@ |
||
| 279 | 279 | public static function getName($context = null): string |
| 280 | 280 | { |
| 281 | 281 | /** @var OptimizedImages $context */ |
| 282 | - return $context->handle . '_OptimizedImages'; |
|
| 282 | + return $context->handle.'_OptimizedImages'; |
|
| 283 | 283 | } |
| 284 | 284 | } |
@@ -63,7 +63,7 @@ |
||
| 63 | 63 | array $params = [], |
| 64 | 64 | string $minifier = null |
| 65 | 65 | ): string { |
| 66 | - $template = 'image-optimize/' . $templatePath; |
|
| 66 | + $template = 'image-optimize/'.$templatePath; |
|
| 67 | 67 | $oldMode = Craft::$app->view->getTemplateMode(); |
| 68 | 68 | // Look for the template on the frontend first |
| 69 | 69 | try { |