rodrigobertin
6/13/2015 - 3:14 PM

rezise image

rezise image

//redimensionar
function rezise($SrcImage, $DestImage, $MaxWidth=980, $MaxHeight=0, $Quality=90) {
  list($iWidth, $iHeight, $type)=getimagesize($SrcImage);
  //echo $type;

  //solo redimensional mayores a 1200
  if ($iWidth>3000 || $iHeight>3000) {

    //=== si no se pone el alto ====//
    if (($MaxHeight == 0) && isset($MaxWidth)) {
      //si no pone alto
      $MaxHeight=($MaxWidth * $iHeight) / $iWidth;
    }

    //==== si no se pone el ancho ==//
    if (($MaxWidth == 0) && isset($MaxHeight)) {
      //si no pone ancho
      $MaxWidth=($MaxHeight * $iWidth) / $iHeight;
    }

    //asignar
    $NewWidth=$MaxWidth;
    $NewHeight=$MaxHeight;
    $NewCanves=imagecreatetruecolor($NewWidth, $NewHeight);

    switch ($type) {
      case 1:
        //gif
        @$finalImage=imagecreatefromgif($SrcImage);
        break;

      case 2:
        //jpeg
        @$finalImage=imagecreatefromjpeg($SrcImage);
        break;

      case 3:
        //png
        @$finalImage=imagecreatefrompng($SrcImage);
        break;
    }


    // Resize Image
    if (@imagecopyresampled($NewCanves, $finalImage, 0, 0, 0, 0, $NewWidth, $NewHeight, $iWidth, $iHeight)) {
      // copy file
      if (@imagejpeg($NewCanves, $DestImage, $Quality)) {
        @imagedestroy($NewCanves);
        @unlink($SrcImage);
        return true;
      }
    }

  }
}