PHP image Flip

Following code will  flip image in vertical/horizontal/both

$imageSrc = imagecreatefrompng(SOURCE_IMAGE_PATH);

$imageSrc = ImageFlip($imageSrc, 3);

imagepng($imageSrc, 'flip.png');

imagedestroy($imageSrc);
/**
 * $imgSrc
 * Image source
 *
 * $mode
 * 1 = vertical
 * 2 = horizontal
 * 3 = both
 */
function ImageFlip($imgSrc, $mode) {

  $width = imagesx($imgSrc);
  $height = imagesy($imgSrc);

  $src_x = 0;
  $src_y = 0;
  $src_width = $width;
  $src_height = $height;

  switch($mode) {
    case '1':
      $src_y = $height -1;
      $src_height = -$height;
    break;

    case '2':
      $src_x = $width -1;
      $src_width = -$width;
    break;

    case '3':
      $src_x = $width -1;
      $src_y = $height -1;
      $src_width = -$width;
      $src_height = -$height;
    break;

    default:
      return $imgSrc;
  }

  $imgdest = imagecreatetruecolor($width, $height);

  imagecolortransparent($imgdest, imagecolorallocate($imgSrc, 0, 0, 0));
  imagealphablending($imgdest, false);
  imagesavealpha($imgdest, true);

  if(imagecopyresampled($imgdest, $imgSrc, 0, 0, $src_x, $src_y , $width, $height, $src_width, $src_height)){
    return $imgdest;
  }

  return $imgSrc;
}