function CenterSquarify(ArgbColor $backgroundColor = null)
    {
        $width = $this->Width();
        $height = $this->Height();
        $squareSize = min($width, $height);
        $xOrigin = 0;
        $yOrigin = 0;
        if ($width > $squareSize)
            $xOrigin = round(($width - $squareSize) / 2) ;
        
        else if ($height > $squareSize)
            $yOrigin = round(($height - $squareSize) / 2);
        
        $destRes = \imagecreatetruecolor($squareSize, $squareSize);
        
        if ($backgroundColor)
        {
            $colRes = \imagecolorallocate($destRes, $backgroundColor->GetRed(), 
                    $backgroundColor->GetGreen(), $backgroundColor->GetBlue());    
            
            \imagefill($destRes, 0, 0, $colRes);
            \imagecolordeallocate($destRes, $colRes);
        }
        \imagecopy($destRes, $this->resource, 0, 0, $xOrigin, $yOrigin, $squareSize, $squareSize);
            
        $this->AssignResource($destRes);
    }
function CenterSquarify(ArgbColor $backgroundColor = null)
    {
        $width = $this->Width();
        $height = $this->Height();
        $squareSize = min($width, $height);
        $xOrigin = 0;
        $yOrigin = 0;
        if ($width > $squareSize)
            $xOrigin = round(($width - $squareSize) / 2) ;
        
        else if ($height > $squareSize)
            $yOrigin = round(($height - $squareSize) / 2);
        
        $destRes = \imagecreatetruecolor($squareSize, $squareSize);
        
        if ($backgroundColor)
        {
            $colRes = \imagecolorallocate($destRes, $backgroundColor->GetRed(), 
                    $backgroundColor->GetGreen(), $backgroundColor->GetBlue());    
            
            \imagefill($destRes, 0, 0, $colRes);
            \imagecolordeallocate($destRes, $colRes);
        }
        \imagecopy($destRes, $this->resource, 0, 0, $xOrigin, $yOrigin, $squareSize, $squareSize);
            
        $this->AssignResource($destRes);
    }
function CenterSquarify ( ArgbColor $ backgroundColor = null ) { $ width = $ this -> Width ( ) ; $ height = $ this -> Height ( ) ; $ squareSize = min ( $ width , $ height ) ; $ xOrigin = 0 ; $ yOrigin = 0 ; if ( $ width > $ squareSize ) $ xOrigin = round ( ( $ width - $ squareSize ) / 2 ) ; else if ( $ height > $ squareSize ) $ yOrigin = round ( ( $ height - $ squareSize ) / 2 ) ; $ destRes = \ imagecreatetruecolor ( $ squareSize , $ squareSize ) ; if ( $ backgroundColor ) { $ colRes = \ imagecolorallocate ( $ destRes , $ backgroundColor -> GetRed ( ) , $ backgroundColor -> GetGreen ( ) , $ backgroundColor -> GetBlue ( ) ) ; \ imagefill ( $ destRes , 0 , 0 , $ colRes ) ; \ imagecolordeallocate ( $ destRes , $ colRes ) ; } \ imagecopy ( $ destRes , $ this -> resource , 0 , 0 , $ xOrigin , $ yOrigin , $ squareSize , $ squareSize ) ; $ this -> AssignResource ( $ destRes ) ; }
Crops the image to the biggest fitting, centered square
Crops the image to the biggest fitting centered square