elFinder\elFinderVolumeDriver::createTmb PHP Méthode

createTmb() protected méthode

Create thumnbnail and return it's URL on success
Author: Dmitry (dio) Levashov
protected createTmb ( string $path, $stat ) : string | false
$path string file path
Résultat string | false
    protected function createTmb($path, $stat)
    {
        if (!$stat || !$this->canCreateTmb($path, $stat)) {
            return false;
        }
        $name = $this->tmbname($stat);
        $tmb = $this->tmbPath . DIRECTORY_SEPARATOR . $name;
        // copy image into tmbPath so some drivers does not store files on local fs
        if (($src = $this->_fopen($path, 'rb')) == false) {
            return false;
        }
        if (($trg = fopen($tmb, 'wb')) == false) {
            $this->_fclose($src, $path);
            return false;
        }
        while (!feof($src)) {
            fwrite($trg, fread($src, 8192));
        }
        $this->_fclose($src, $path);
        fclose($trg);
        $result = false;
        $tmbSize = $this->tmbSize;
        if (($s = getimagesize($tmb)) == false) {
            return false;
        }
        /* If image smaller or equal thumbnail size - just fitting to thumbnail square */
        if ($s[0] <= $tmbSize && $s[1] <= $tmbSize) {
            $result = $this->imgSquareFit($tmb, $tmbSize, $tmbSize, 'center', 'middle', $this->options['tmbBgColor'], 'png');
        } else {
            if ($this->options['tmbCrop']) {
                /* Resize and crop if image bigger than thumbnail */
                if (!($s[0] > $tmbSize && $s[1] <= $tmbSize || $s[0] <= $tmbSize && $s[1] > $tmbSize) || $s[0] > $tmbSize && $s[1] > $tmbSize) {
                    $result = $this->imgResize($tmb, $tmbSize, $tmbSize, true, false, 'png');
                }
                if (($s = getimagesize($tmb)) != false) {
                    $x = $s[0] > $tmbSize ? intval(($s[0] - $tmbSize) / 2) : 0;
                    $y = $s[1] > $tmbSize ? intval(($s[1] - $tmbSize) / 2) : 0;
                    $result = $this->imgCrop($tmb, $tmbSize, $tmbSize, $x, $y, 'png');
                }
            } else {
                $result = $this->imgResize($tmb, $tmbSize, $tmbSize, true, true, $this->imgLib, 'png');
            }
            $result = $this->imgSquareFit($tmb, $tmbSize, $tmbSize, 'center', 'middle', $this->options['tmbBgColor'], 'png');
        }
        if (!$result) {
            unlink($tmb);
            return false;
        }
        return $name;
    }