private function normalizeTransform($transform): array
    {
        // if resize mode is not crop or croponly, remove position
        if (isset($transform['mode'], $transform['position']) && (($transform['mode'] !== 'crop') && ($transform['mode'] !== 'croponly'))) {
            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']) && (\is_float($transform['ratio']) || \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']);
                }
            }
        }

        // if transform is in Craft's named version, convert to percentage
        if (isset($transform['position'])) {

            if (\is_array($transform['position']) && isset($transform['position']['x']) && isset($transform['position']['y'])) {
                $transform['position'] = ($transform['position']['x'] * 100).' '.($transform['position']['y'] * 100);
            }

            if (isset(self::$craftPositionTranslate[(string)$transform['position']])) {
                $transform['position'] = self::$craftPositionTranslate[(string)$transform['position']];
            }

            $transform['position'] = str_replace('%', '', (string)$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 = ImagerHelpers::moveArrayKeyToPos('mode', 0, $transform);
        $transform = ImagerHelpers::moveArrayKeyToPos('height', 0, $transform);
        $transform = ImagerHelpers::moveArrayKeyToPos('width', 0, $transform);
        $transform = ImagerHelpers::moveArrayKeyToPos('preEffects', 99, $transform);
        $transform = ImagerHelpers::moveArrayKeyToPos('effects', 99, $transform);
        $transform = ImagerHelpers::moveArrayKeyToPos('watermark', 99, $transform);

        return $transform;
    }