        $targetW = self::intRound($image->width * $scale);
        $targetH = self::intRound($image->height * $scale);

        self::adjustDimensions($sourceX, $sourceW, $targetX, $targetW, $outputW, $scale, $options['pad'], $options['align-x']);
        self::adjustDimensions($sourceY, $sourceH, $targetY, $targetH, $outputH, $scale, $options['pad'], $options['align-y']);

        // create output image
        $output = Image::blank($outputW, $outputH);

        // enable transparency
        if ($options['trans']) {
            $output->enableAlpha();
        } elseif ($options['bgcolor'] !== null) {