Modx. phpThumbOn / phpThumbOf cuts to square when specifying only width or height

I wrote a snippet that collects photos from the specified folder, cuts the photo (phpThumbOn) to the desired size and makes it a gallery on Fancybox:

<?php

// requires phpThumbOn
// OPTIONS

// &folder
// &justified   (default = null)
// &fancybox    (default = default)
// &w           (default = 200)
// &h           (default = 300)
// &W           (default = null)
// &H           (default = null)

$folder = str_replace("assets/","",$folder);
$path = "assets/$folder";
$flag = false;
$dir_i = (is_dir($path) && is_readable($path)) ? new DirectoryIterator($path) : array();
$fancyboxAttr = "";

if ($justified == 1) echo '<div class="gridzy">';


// On/Off Fancybox
if ($fancybox == 1) {
    if (!empty($id)) $fancyboxAttr = "data-fancybox='".$id."'";
    else    $fancyboxAttr = "data-fancybox='default'";
}



foreach ($dir_i as $f) {
        if($f->isFile() && $f->isReadable()){
                $flag = true;
                $input = $path.'/'.$f->getFilename();


                // THUMBNAIL RESIZE
                if (empty($w) && empty($h)) {$options = "w=300&h=200&zc=1&q=90";}
                else {
                    if (empty($w) || empty($h)) {
                        if      (empty($w)) {$options = "h=".$h."&zc=1&q=90";} 
                        else if (empty($h)) {$options = "w=".$w."&zc=1&q=90";}
                    } else $options = "w=".$w."&h=".$h."&zc=1&q=90";

                }
                $thumbnail = $modx->runSnippet("phpthumbon",array('input' => $input, 'options' => $options));

                if ($fancybox == 1) {
                    // FULL RESIZE
                    if (!empty($W) || !empty($H)) {
                        if      (empty($W)) {$Options = "h=".$H."&zc=1&q=90";}
                        else if (empty($H)) {$Options = "w=".$W."&zc=1&q=90";}
                        else $Options = "w=".$W."&h=".$H."&zc=1&q=90";
                        $input = $modx->runSnippet("phpthumbon",array('input' => $input, 'options' => $Options));
                    }
                }

                if ($fancybox == 1) {echo '<a '.$fancyboxAttr.' href="'.$input.'"><img src="'.$thumbnail.'"> </a>';echo "\n";}
                else {echo '<img src="'.$thumbnail.'">';echo "\n";}

        }
}


if ($justified == 1) echo '</div>';
if(!$flag) {
    echo '<img src="assets/images/no_image.jpg">'; 
}

On the locale (OpenServer / php 7.4) it works perfectly. On the hosting (tried it nic.ru and fozzy.com) the problem is that if you specify only the width or height for resizing, then phpThumbOn cuts on both sides, i.e. into a square, while it should only cut one side and keep the proportions of the original one images.

Imagick and GD are included, tried on all PCP versions from 5.6 to 7.4.

Author: aleksandr barakin, 2020-06-12