Skip to content

Instantly share code, notes, and snippets.

@rodrigobertin
Created June 13, 2015 15:14
Show Gist options
  • Save rodrigobertin/60617a76a1c7c9be64c5 to your computer and use it in GitHub Desktop.
Save rodrigobertin/60617a76a1c7c9be64c5 to your computer and use it in GitHub Desktop.
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;
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment