| @@ -1,8 +1,9 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | namespace Depicter\Document\Models\Elements; |
| 3 | 3 | |
| 4 | 4 | use Averta\Core\Utility\Data; |
| 5 | +use Averta\Core\Utility\Media; | |
| 5 | 6 | use Averta\WordPress\Utility\JSON; |
| 6 | 7 | use Depicter; |
| 7 | 8 | use Depicter\Document\CSS\Breakpoints; |
| 8 | 9 | use Depicter\Document\Models; |
| @@ -141,9 +142,9 @@ | ||
| 141 | 142 | continue; |
| 142 | 143 | } |
| 143 | 144 | $originalMediaWidth = $attachment[1] ?: $mediaWidth; |
| 144 | 145 | $originalMediaHeight = $attachment[2] ?: $mediaHeight; |
| 145 | - [ $mediaWidth, $mediaHeight ] = $this->fitToSourceMedia( 'contain', $mediaWidth, $mediaHeight, $originalMediaWidth, $originalMediaHeight ); | |
| 146 | + [ $mediaWidth, $mediaHeight ] = Media::fitInBox( 'contain', $mediaWidth, $mediaHeight, $originalMediaWidth, $originalMediaHeight ); | |
| 146 | 147 | } |
| 147 | 148 | |
| 148 | 149 | $args[ $dataAttrName ] = [ |
| 149 | 150 | 'mediaSize'=> [ |
| @@ -299,9 +300,9 @@ | ||
| 299 | 300 | return; |
| 300 | 301 | } |
| 301 | 302 | $originalMediaWidth = $attachment[1] ?: null; |
| 302 | 303 | $originalMediaHeight = $attachment[2] ?: null; |
| 303 | - [ $mediaWidth, $mediaHeight ] = $this->fitToSourceMedia( 'contain', $this->inheritedOptions['resizeW'], $this->inheritedOptions['resizeH'], $originalMediaWidth, $originalMediaHeight ); | |
| 304 | + [ $mediaWidth, $mediaHeight ] = Media::fitInBox( 'contain', $this->inheritedOptions['resizeW'], $this->inheritedOptions['resizeH'], $originalMediaWidth, $originalMediaHeight ); | |
| 304 | 305 | $params[] = $mediaWidth; |
| 305 | 306 | $params[] = $mediaHeight; |
| 306 | 307 | |
| 307 | 308 | } else { |
| @@ -448,31 +449,7 @@ | ||
| 448 | 449 | } |
| 449 | 450 | $this->appendSourceTag( $desktopSources, 'min-width', $mediaQuerySize ); |
| 450 | 451 | } |
| 451 | 452 | |
| 452 | - } | |
| 453 | - | |
| 454 | - /** | |
| 455 | - * Fit image to source image with and height | |
| 456 | - * Mostly used in data source images | |
| 457 | - * | |
| 458 | - * @param $type | |
| 459 | - * @param $sourceMediaWidth | |
| 460 | - * @param $sourceMediaHeight | |
| 461 | - * @param $width | |
| 462 | - * @param $height | |
| 463 | - * | |
| 464 | - * @return float[]|int[] | |
| 465 | - */ | |
| 466 | - protected function fitToSourceMedia( $type, $sourceMediaWidth, $sourceMediaHeight, $width, $height ) { | |
| 467 | - $withRatio = $sourceMediaWidth / $width; | |
| 468 | - $heightRatio = $sourceMediaHeight / $height; | |
| 469 | - | |
| 470 | - $ratio = $type === 'cover' ? max($withRatio, $heightRatio) : min($withRatio, $heightRatio); | |
| 471 | - | |
| 472 | - return [ | |
| 473 | - $width * $ratio, | |
| 474 | - $height * $ratio, | |
| 475 | - ]; | |
| 476 | 453 | } |
| 477 | 454 | |
| 478 | 455 | } |