Bueno estoy teniendo problemas para hacer esas 3 cosas a la vez. Logré resizear la imagen y llevarla a otra ruta.
Pero... necesito cambiarle el nombre por una variable id. que representa a la foto de cada usuario. La cosa es que no se como también cambiarle el nombre.
El archivo 1 contiene esto..
Código :
<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> </head> <body> <form method="post" action="2.php" id="formulario1" enctype="multipart/form-data"> <fieldset id="recuformulario"> <legend>Redimensionar una imagen en el servidor (Thumbnail)</legend> <p><label for="mail">Seleccione imagen:</label> <input type="file" name="imagen" id="imagen"</p> <p><input type="submit" value="Confirmar" id="confirmar"></p> </fieldset> </form> </body> </html>
el archivo 2 contiene :
Código :
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<?php
copy($_FILES['imagen']['tmp_name'],$_FILES['imagen']['name']);
move_uploaded_file($_FILES['imagen']['tmp_name'],'img/2.jpg');
require('3.php');
$thum1=new Thumbnail($_FILES['imagen']['name'],100,100);
$thum1->guardar('img/xxx'.$_FILES['imagen']['name']);
$thum1->redimensionar(0.50);
$thum1->guardar('img/yyy'.$_FILES['imagen']['name']);
?>
</body>
</html>
y el archivo 3 contiene
Código :
<?php
class Thumbnail {
private $archi;
private $extension;
private $ancho;
private $alto;
public function __construct($archi,$ancho=100,$alto=100)
{
$this->archi=$archi;
$vec=explode('.',$archi);
$this->extension=strtoupper($vec[sizeof($vec)-1]);
$this->ancho=$ancho;
$this->alto=$alto;
}
private function guardarEnDisco($imagen,$archinuevo)
{
$vec=explode('.',$archinuevo);
$ext=strtoupper($vec[sizeof($vec)-1]);
switch ($ext) {
case "PNG":
imagepng($imagen,$archinuevo);
break;
case "GIF":
imagegif($imagen,$archinuevo);
break;
case "JPG":;
case "JPEG":
imagejpeg($imagen,$archinuevo);
break;
}
}
public function guardar($archinue)
{
$tam=getimagesize($this->archi);
$imagen=imagecreatetruecolor($this->ancho,$this->alto);
switch ($this->extension) {
case "PNG":
$origen=imagecreatefrompng($this->archi);
imagecopyresampled($imagen,$origen,0,0,0,0,$this->ancho,$this->alto,$tam[0],$tam[1]);
$this->guardarEnDisco($imagen,$archinue);
break;
case "GIF":
$origen=imagecreatefromgif($this->archi);
imagecopyresampled($imagen,$origen,0,0,0,0,$this->ancho,$this->alto,$tam[0],$tam[1]);
$this->guardarEnDisco($imagen,$archinue);
break;
case "JPG":;
case "JPEG":
$origen=imagecreatefromjpeg($this->archi);
imagecopyresampled($imagen,$origen,0,0,0,0,$this->ancho,$this->alto,$tam[0],$tam[1]);
$this->guardarEnDisco($imagen,$archinue);
break;
}
}
public function redimensionar($porc)
{
$tam=getimagesize($this->archi);
$this->ancho=$tam[0]*$porc;
$this->alto=$tam[1]*$porc;
}
} ?>
Espero su ayuda. Muchas gracias
