Craft\ImagerService::_normalizeTransform PHP Method

_normalizeTransform() private method

Normalize transform object and values
private _normalizeTransform ( $transform, $paths = null ) : mixed
$transform
$paths
return mixed
    private function _normalizeTransform($transform, $paths = null)
    {
        // if resize mode is not crop or croponly, remove position
        if (isset($transform['mode']) && ($transform['mode'] != 'crop' && $transform['mode'] != 'croponly')) {
            if (isset($transform['position'])) {
                unset($transform['position']);
            }
        }
        // if quality is used, assume it's jpegQuality
        if (isset($transform['quality'])) {
            $value = $transform['quality'];
            unset($transform['quality']);
            if (!isset($transform['jpegQuality'])) {
                $transform['jpegQuality'] = $value;
            }
        }
        // if ratio is set, and width or height is missing, calculate missing size
        if (isset($transform['ratio']) and (is_float($transform['ratio']) or is_int($transform['ratio']))) {
            if (isset($transform['width']) && !isset($transform['height'])) {
                $transform['height'] = round($transform['width'] / $transform['ratio']);
                unset($transform['ratio']);
            } else {
                if (isset($transform['height']) && !isset($transform['width'])) {
                    $transform['width'] = round($transform['height'] * $transform['ratio']);
                    unset($transform['ratio']);
                } else {
                    // neither is set, use width from original image
                    if ($paths !== null) {
                        $originalSize = getimagesize($paths->sourcePath . $paths->sourceFilename);
                        $transform['width'] = $originalSize[0];
                        $transform['height'] = round($transform['width'] / $transform['ratio']);
                        unset($transform['ratio']);
                    }
                }
            }
        }
        // remove format, this is already in the extension
        if (isset($transform['format'])) {
            unset($transform['format']);
        }
        // if transform is in Craft's named version, convert to percentage
        if (isset($transform['position'])) {
            if (isset(ImagerService::$craftPositonTranslate[$transform['position']])) {
                $transform['position'] = ImagerService::$craftPositonTranslate[$transform['position']];
            }
            $transform['position'] = str_replace('%', '', $transform['position']);
        }
        // sort keys to get them in the same order
        ksort($transform);
        // Move certain keys around abit to make the filename a bit more sane when viewed unencoded
        $transform = $this->_moveArrayKeyToPos('mode', 0, $transform);
        $transform = $this->_moveArrayKeyToPos('height', 0, $transform);
        $transform = $this->_moveArrayKeyToPos('width', 0, $transform);
        $transform = $this->_moveArrayKeyToPos('preEffects', 99, $transform);
        $transform = $this->_moveArrayKeyToPos('effects', 99, $transform);
        $transform = $this->_moveArrayKeyToPos('watermark', 99, $transform);
        return $transform;
    }