public final function cropRect( Rectangle $rect, bool $internal = true )
      : IImage
   {

      $thumb = \imagecreatetruecolor( $rect->size->getWidth(), $rect->size->getHeight() );

      if ( $this->mimeType == 'image/gif' || $this->mimeType == 'image/png')
      {
         \imagealphablending( $thumb, false );
         \imagesavealpha( $thumb, true );
      }

      \imagecopyresampled(
         $thumb,              # $dst_image
         $this->r,            # $src_image
         0,                   # $dst_x
         0,                   # $dst_y
         $rect->point->x,     # $src_x
         $rect->point->y,     # $src_y
         $rect->size->getWidth(),  # $dst_w
         $rect->size->getHeight(), # $dst_h
         $rect->size->getWidth(),  # $src_w
         $rect->size->getHeight()  # $src_h
      );

      if ( $internal )
      {
         $this->size->setHeight( $rect->size->getHeight() );
         $this->size->setWidth ( $rect->size->getWidth() );
         if ( \is_resource( $this->r ) )
         {
            \imagedestroy( $this->r );
            $this->r = null;
         }
         $this->r = $thumb;
         return $this;
      }

      return new GdImage( $thumb, $rect->size, $this->mimeType, $this->_file );

   }
public final function cropRect( Rectangle $rect, bool $internal = true )
      : IImage
   {

      $thumb = \imagecreatetruecolor( $rect->size->getWidth(), $rect->size->getHeight() );

      if ( $this->mimeType == 'image/gif' || $this->mimeType == 'image/png')
      {
         \imagealphablending( $thumb, false );
         \imagesavealpha( $thumb, true );
      }

      \imagecopyresampled(
         $thumb,              # $dst_image
         $this->r,            # $src_image
         0,                   # $dst_x
         0,                   # $dst_y
         $rect->point->x,     # $src_x
         $rect->point->y,     # $src_y
         $rect->size->getWidth(),  # $dst_w
         $rect->size->getHeight(), # $dst_h
         $rect->size->getWidth(),  # $src_w
         $rect->size->getHeight()  # $src_h
      );

      if ( $internal )
      {
         $this->size->setHeight( $rect->size->getHeight() );
         $this->size->setWidth ( $rect->size->getWidth() );
         if ( \is_resource( $this->r ) )
         {
            \imagedestroy( $this->r );
            $this->r = null;
         }
         $this->r = $thumb;
         return $this;
      }

      return new GdImage( $thumb, $rect->size, $this->mimeType, $this->_file );

   }
public final function cropRect ( Rectangle $ rect , bool $ internal = true ) : IImage { $ thumb = \ imagecreatetruecolor ( $ rect -> size -> getWidth ( ) , $ rect -> size -> getHeight ( ) ) ; if ( $ this -> mimeType == 'image/gif' || $ this -> mimeType == 'image/png' ) { \ imagealphablending ( $ thumb , false ) ; \ imagesavealpha ( $ thumb , true ) ; } \ imagecopyresampled ( $ thumb , # $dst_image $ this -> r , # $src_image 0 , # $dst_x 0 , # $dst_y $ rect -> point -> x , # $src_x $ rect -> point -> y , # $src_y $ rect -> size -> getWidth ( ) , # $dst_w $ rect -> size -> getHeight ( ) , # $dst_h $ rect -> size -> getWidth ( ) , # $src_w $ rect -> size -> getHeight ( ) # $src_h ) ; if ( $ internal ) { $ this -> size -> setHeight ( $ rect -> size -> getHeight ( ) ) ; $ this -> size -> setWidth ( $ rect -> size -> getWidth ( ) ) ; if ( \ is_resource ( $ this -> r ) ) { \ imagedestroy ( $ this -> r ) ; $ this -> r = null ; } $ this -> r = $ thumb ; return $ this ; } return new GdImage ( $ thumb , $ rect -> size , $ this -> mimeType , $ this -> _file ) ; }
Crop the defined image part and returns the current or new image instance.

@param  \Beluga\Drawing\Rectangle $rect
@param  boolean               $internal Do not create a new instance?
@return \Beluga\Drawing\Image\IImage
Crop the defined image part and returns the current or new image instance .