private function getDimensions(\media_subdef $subdef)
    {
        $outWidth = $subdef->get_width();
        $outHeight = $subdef->get_height() | $outWidth;

        $thumbnail_height = $subdef->get_height() > 0 ? $subdef->get_height() : 120;
        $thumbnail_width = $subdef->get_width() > 0 ? $subdef->get_width() : 120;

        $subdefRatio = 0;
        $thumbnailRatio = $thumbnail_width / $thumbnail_height;
        if ($outWidth > 0 && $outHeight > 0) {
            $subdefRatio = $outWidth / $outHeight;
        }

        if ($thumbnailRatio > $subdefRatio) {
            if ($outWidth > $thumbnail_width) {
                $outWidth = $thumbnail_width;
            }
            $outHeight = $outWidth / $thumbnail_width * $thumbnail_height;
            $top = ($outHeight - $outHeight) / 2;
        } else {
            if ($outHeight > $thumbnail_height) {
                $outHeight = $thumbnail_height;
            }
            $outWidth = $outHeight * $thumbnail_width / $thumbnail_height;
            $top = (($outHeight - $outHeight) / 2);
        }

        return [
            'width'  => round($outWidth),
            'height' => round($outHeight),
            'top'    => $top
        ];
    }
private function getDimensions(\media_subdef $subdef)
    {
        $outWidth = $subdef->get_width();
        $outHeight = $subdef->get_height() | $outWidth;

        $thumbnail_height = $subdef->get_height() > 0 ? $subdef->get_height() : 120;
        $thumbnail_width = $subdef->get_width() > 0 ? $subdef->get_width() : 120;

        $subdefRatio = 0;
        $thumbnailRatio = $thumbnail_width / $thumbnail_height;
        if ($outWidth > 0 && $outHeight > 0) {
            $subdefRatio = $outWidth / $outHeight;
        }

        if ($thumbnailRatio > $subdefRatio) {
            if ($outWidth > $thumbnail_width) {
                $outWidth = $thumbnail_width;
            }
            $outHeight = $outWidth / $thumbnail_width * $thumbnail_height;
            $top = ($outHeight - $outHeight) / 2;
        } else {
            if ($outHeight > $thumbnail_height) {
                $outHeight = $thumbnail_height;
            }
            $outWidth = $outHeight * $thumbnail_width / $thumbnail_height;
            $top = (($outHeight - $outHeight) / 2);
        }

        return [
            'width'  => round($outWidth),
            'height' => round($outHeight),
            'top'    => $top
        ];
    }
private function getDimensions ( \ media_subdef $ subdef ) { $ outWidth = $ subdef -> get_width ( ) ; $ outHeight = $ subdef -> get_height ( ) | $ outWidth ; $ thumbnail_height = $ subdef -> get_height ( ) > 0 ? $ subdef -> get_height ( ) : 120 ; $ thumbnail_width = $ subdef -> get_width ( ) > 0 ? $ subdef -> get_width ( ) : 120 ; $ subdefRatio = 0 ; $ thumbnailRatio = $ thumbnail_width / $ thumbnail_height ; if ( $ outWidth > 0 && $ outHeight > 0 ) { $ subdefRatio = $ outWidth / $ outHeight ; } if ( $ thumbnailRatio > $ subdefRatio ) { if ( $ outWidth > $ thumbnail_width ) { $ outWidth = $ thumbnail_width ; } $ outHeight = $ outWidth / $ thumbnail_width * $ thumbnail_height ; $ top = ( $ outHeight - $ outHeight ) / 2 ; } else { if ( $ outHeight > $ thumbnail_height ) { $ outHeight = $ thumbnail_height ; } $ outWidth = $ outHeight * $ thumbnail_width / $ thumbnail_height ; $ top = ( ( $ outHeight - $ outHeight ) / 2 ) ; } return [ 'width' => round ( $ outWidth ) , 'height' => round ( $ outHeight ) , 'top' => $ top ] ; }
Php raw implementation of thumbnails.html.twig macro
@param \media_subdef $subdef
@return array
Php raw implementation of thumbnails . html . twig macro