Skip to content

Instantly share code, notes, and snippets.

@BenjaminGuV
Created June 25, 2012 23:34
Show Gist options
  • Save BenjaminGuV/2992098 to your computer and use it in GitHub Desktop.
Save BenjaminGuV/2992098 to your computer and use it in GitHub Desktop.
cambiar de tamaño las imagenes
<?php
$destino = "/var/www/Guardar/";
$destino2 = "/Guardar/";
$filetype = $_FILES['file']['type'];
$type = substr($filetype, (strpos($filetype,"/"))+1);
$types=array("jpeg","gif","png", "jpg");
if(in_array($type, $types)){
if(isset($_FILES['file'])){
$nombre = $_FILES['file']['name'];
$temp = $_FILES['file']['tmp_name'];
// subir imagen al servidor
if(move_uploaded_file($temp, $destino.$nombre))
{
echo $destino2 . $nombre;
$datos = getimagesize( $destino.$nombre );
$xp = $datos[0];
$yp = $datos[1];
CreateThumb( $destino.$nombre, $destino.$nombre, $xp, $yp, 100, 100, 75 );
}
//echo $destino . $nombre;
}
}else{
echo "false";
}
function CreateThumb($pImageOrigen, $pImageDestino, $pWidth, $pHeight, $pMaxWidth, $pMaxHeight, $pCalidad){
// SI WIDTH ES MAS ALTO, LO CORTO POR WIDTH Y VICEVERSA
if($pWidth > $pHeight){
$_porcentaje = $pMaxHeight*100/$pHeight;
$_height = $pMaxHeight;
$_width = ceil($_porcentaje*$pWidth/100);
}else{
$_porcentaje = $pMaxWidth*100/$pWidth;
$_width = $pMaxWidth;
$_height = ceil($_porcentaje*$pHeight/100);
}
$_pic = @imagecreatefromjpeg($pImageOrigen);
$_tmp = imagecreatetruecolor($pMaxWidth, $pMaxHeight);
imagecopyresized($_tmp, $_pic, 0, 0, 0, 0, $_width, $_height, $pWidth, $pHeight);
imagejpeg($_tmp, $pImageDestino, $pCalidad);
imagedestroy($_pic);
imagedestroy($_tmp);
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment