original_string: public function crop($width, $height, $mode = 'tl')
      {
          if ( !is_numeric($width) ) {
              throw new \InvalidArgumentException('$width must be numeric');
          }
  
          if ( !is_numeric($height) ) {
              throw new \InvalidArgumentException('$height must be numeric');
          }
  
          if ( $this->newImage )
          {
              $this->sourceImage = $this->newImage;
          }
  
          $oldWidth   = ($this->newImage) ? imagesx($this->newImage) : $this->source['width'];
          $oldHeight  = ($this->newImage) ? imagesy($this->newImage) : $this->source['height'];
  
          $this->create($width, $height);
  
          $startX     = $startY = 0;
          $cropWidth  = $sourceWidth  = $width;
          $cropHeight = $sourceHeight = $height;
  
          if ( is_array($mode) )
          {
              $startX = $mode[0];
              $startY = $mode[1];
          }
  
          if ($mode === self::CROP_TOP_CENTER)
          {
              $startX = ($oldWidth - $cropWidth) / 2;
          }
          else if ($mode === self::CROP_TOP_RIGHT)
          {
              $startX = $oldWidth - $cropWidth;
          }
          else if ($mode === self::CROP_CENTER_LEFT)
          {
              $startY = ($oldHeight - $cropHeight) / 2;
          }
          else if ($mode === self::CROP_CENTER_CENTER)
          {
              $startX = ($oldWidth - $cropWidth)   / 2;
              $startY = ($oldHeight - $cropHeight) / 2;
          }
          else if ($mode === self::CROP_CENTER_RIGHT)
          {
              $startX = $oldWidth - $cropWidth;
              $startY = ($oldHeight - $cropHeight) / 2;
          }
          else if ($mode === self::CROP_BOTTOM_LEFT)
          {
              $startY = $oldHeight - $cropHeight;
          }
          else if ($mode === self::CROP_BOTTOM_CENTER)
          {
              $startX = ($oldWidth - $cropWidth)   / 2;
              $startY = $oldHeight - $cropHeight;
          }
          else if ($mode === self::CROP_BOTTOM_RIGHT)
          {
              $startX = $oldWidth - $cropWidth;
              $startY = $oldHeight - $cropHeight;
          }
          else
          {
          }
  
          imagecopyresampled(
              $this->newImage,
              $this->sourceImage,
              0, 0, $startX, $startY,
              $cropWidth, $cropHeight, $sourceWidth, $sourceHeight);
  
          return $this;
      }
code: public function crop($width, $height, $mode = 'tl')
      {
          if ( !is_numeric($width) ) {
              throw new \InvalidArgumentException('$width must be numeric');
          }
  
          if ( !is_numeric($height) ) {
              throw new \InvalidArgumentException('$height must be numeric');
          }
  
          if ( $this->newImage )
          {
              $this->sourceImage = $this->newImage;
          }
  
          $oldWidth   = ($this->newImage) ? imagesx($this->newImage) : $this->source['width'];
          $oldHeight  = ($this->newImage) ? imagesy($this->newImage) : $this->source['height'];
  
          $this->create($width, $height);
  
          $startX     = $startY = 0;
          $cropWidth  = $sourceWidth  = $width;
          $cropHeight = $sourceHeight = $height;
  
          if ( is_array($mode) )
          {
              $startX = $mode[0];
              $startY = $mode[1];
          }
  
          if ($mode === self::CROP_TOP_CENTER)
          {
              $startX = ($oldWidth - $cropWidth) / 2;
          }
          else if ($mode === self::CROP_TOP_RIGHT)
          {
              $startX = $oldWidth - $cropWidth;
          }
          else if ($mode === self::CROP_CENTER_LEFT)
          {
              $startY = ($oldHeight - $cropHeight) / 2;
          }
          else if ($mode === self::CROP_CENTER_CENTER)
          {
              $startX = ($oldWidth - $cropWidth)   / 2;
              $startY = ($oldHeight - $cropHeight) / 2;
          }
          else if ($mode === self::CROP_CENTER_RIGHT)
          {
              $startX = $oldWidth - $cropWidth;
              $startY = ($oldHeight - $cropHeight) / 2;
          }
          else if ($mode === self::CROP_BOTTOM_LEFT)
          {
              $startY = $oldHeight - $cropHeight;
          }
          else if ($mode === self::CROP_BOTTOM_CENTER)
          {
              $startX = ($oldWidth - $cropWidth)   / 2;
              $startY = $oldHeight - $cropHeight;
          }
          else if ($mode === self::CROP_BOTTOM_RIGHT)
          {
              $startX = $oldWidth - $cropWidth;
              $startY = $oldHeight - $cropHeight;
          }
          else
          {
          }
  
          imagecopyresampled(
              $this->newImage,
              $this->sourceImage,
              0, 0, $startX, $startY,
              $cropWidth, $cropHeight, $sourceWidth, $sourceHeight);
  
          return $this;
      }
code_tokens: public function crop ( $ width , $ height , $ mode = 'tl' ) { if ( ! is_numeric ( $ width ) ) { throw new \ InvalidArgumentException ( '$width must be numeric' ) ; } if ( ! is_numeric ( $ height ) ) { throw new \ InvalidArgumentException ( '$height must be numeric' ) ; } if ( $ this -> newImage ) { $ this -> sourceImage = $ this -> newImage ; } $ oldWidth = ( $ this -> newImage ) ? imagesx ( $ this -> newImage ) : $ this -> source [ 'width' ] ; $ oldHeight = ( $ this -> newImage ) ? imagesy ( $ this -> newImage ) : $ this -> source [ 'height' ] ; $ this -> create ( $ width , $ height ) ; $ startX = $ startY = 0 ; $ cropWidth = $ sourceWidth = $ width ; $ cropHeight = $ sourceHeight = $ height ; if ( is_array ( $ mode ) ) { $ startX = $ mode [ 0 ] ; $ startY = $ mode [ 1 ] ; } if ( $ mode === self :: CROP_TOP_CENTER ) { $ startX = ( $ oldWidth - $ cropWidth ) / 2 ; } else if ( $ mode === self :: CROP_TOP_RIGHT ) { $ startX = $ oldWidth - $ cropWidth ; } else if ( $ mode === self :: CROP_CENTER_LEFT ) { $ startY = ( $ oldHeight - $ cropHeight ) / 2 ; } else if ( $ mode === self :: CROP_CENTER_CENTER ) { $ startX = ( $ oldWidth - $ cropWidth ) / 2 ; $ startY = ( $ oldHeight - $ cropHeight ) / 2 ; } else if ( $ mode === self :: CROP_CENTER_RIGHT ) { $ startX = $ oldWidth - $ cropWidth ; $ startY = ( $ oldHeight - $ cropHeight ) / 2 ; } else if ( $ mode === self :: CROP_BOTTOM_LEFT ) { $ startY = $ oldHeight - $ cropHeight ; } else if ( $ mode === self :: CROP_BOTTOM_CENTER ) { $ startX = ( $ oldWidth - $ cropWidth ) / 2 ; $ startY = $ oldHeight - $ cropHeight ; } else if ( $ mode === self :: CROP_BOTTOM_RIGHT ) { $ startX = $ oldWidth - $ cropWidth ; $ startY = $ oldHeight - $ cropHeight ; } else { } imagecopyresampled ( $ this -> newImage , $ this -> sourceImage , 0 , 0 , $ startX , $ startY , $ cropWidth , $ cropHeight , $ sourceWidth , $ sourceHeight ) ; return $ this ; }
docstring: Crop image file
  
  @param int $width
  @param int $height
  @param string $mode tl
  @return $this
docstring_tokens: Crop image file