Foros del Web » Programando para Internet » PHP »

Cómo incorporar este sello de agua ??

Estas en el tema de Cómo incorporar este sello de agua ?? en el foro de PHP en Foros del Web. Estimados: Quiero subir unas fotos y a su vez, incorporarle un sello de agua; tengo las dos cosas que me funcionan por separado pero al ...
  #1 (permalink)  
Antiguo 06/06/2007, 15:45
Avatar de AJVEvoluzione  
Fecha de Ingreso: agosto-2004
Ubicación: Buenos Aires
Mensajes: 195
Antigüedad: 19 años, 7 meses
Puntos: 1
Exclamación Cómo incorporar este sello de agua ??

Estimados:
Quiero subir unas fotos y a su vez, incorporarle un sello de agua; tengo las dos cosas que me funcionan por separado pero al intentar unirlas me da error o simplemente no hace nada además no me guarda la imagen con el sello, si alguien me da una mano y me une esto se lo agradeceré

Subir foto y crear miniatura:

Código PHP:
<?php
define 
("MAX_SIZE","10000"); 
define ("WIDTH","150"); 
define ("HEIGHT","100"); 

function 
make_thumb($img_name,$filename,$new_w,$new_h)
{
$ext=getExtension($img_name);
if(!
strcmp("jpg",$ext) || !strcmp("jpeg",$ext))
$src_img=imagecreatefromjpeg($img_name);

if(!
strcmp("png",$ext))
$src_img=imagecreatefrompng($img_name);

$old_x=imageSX($src_img);
$old_y=imageSY($src_img);

$ratio1=$old_x/$new_w;
$ratio2=$old_y/$new_h;
if(
$ratio1>$ratio2) {
$thumb_w=$new_w;
$thumb_h=$old_y/$ratio1;
}
else {
$thumb_h=$new_h;
$thumb_w=$old_x/$ratio2;
}

$dst_img=ImageCreateTrueColor($thumb_w,$thumb_h);

imagecopyresampled($dst_img,$src_img,0,0,0,0,$thumb_w,$thumb_h,$old_x,$old_y); 

if(!
strcmp("png",$ext))
imagepng($dst_img,$filename); 
else
imagejpeg($dst_img,$filename); 

imagedestroy($dst_img); 
imagedestroy($src_img); 
}

function 
getExtension($str) {
$i strrpos($str,".");
if (!
$i) { return ""; }
$l strlen($str) - $i;
$ext substr($str,$i+1,$l);
return 
$ext;
}


$errors=0;

if(isset(
$_POST['Submit']))
{

$image=$_FILES['image']['name'];

if (
$image
{
$filename stripslashes($_FILES['image']['name']);

$extension getExtension($filename);
$extension strtolower($extension);
if ((
$extension != "jpg") && ($extension != "jpeg") && ($extension != "JPG") && ($extension != "JPEG") && ($extension != "PNG") && ($extension != "png")) 
{
echo 
'<h1>Solo se pueden subir archivos .JPG .GIF o .PNG !!</h1>';
$errors=1;
}
else
{

$size=getimagesize($_FILES['image']['tmp_name']);
$sizekb=filesize($_FILES['image']['tmp_name']);

if (
$sizekb MAX_SIZE*10000)
{
echo 
'<h1>El tamaño de la foto es demaciado grande !!</h1>';
$errors=1;
}


$image_name$filename;
$newname="images/".$image_name;
$copied copy($_FILES['image']['tmp_name'], $newname);
if (!
$copied
{
echo 
'<h1>NO se pudo completar la copia !!</h1>';
$errors=1;
}
else
{
$thumb_name='images/thumbs/'.$image_name;
$thumb=make_thumb($newname,$thumb_name,WIDTH,HEIGHT);
}} }}

if(isset(
$_POST['Submit']) && !$errors
{
echo 
"<h1>Miniatura creada con éxito !!</h1>";
echo 
'<img src="'.$thumb_name.'">';
}

?>
<!-- next comes the form, you must set the enctype to "multipart/form-data" and use an input type "file" -->

<form name="newad" method="post" enctype="multipart/form-data" action="">
<table>
<tr><td><input type="file" name="image" ></td></tr>
<tr><td><input name="Submit" type="submit" value="Subir"></td></tr>
</table> 
</form>
Incorporacion de Sello de Agua:

Código PHP:
$imagesource $_GET['image'];
$filetype substr($imagesource,strlen($imagesource)-4,4); 
$filetype strtolower($filetype); 
if(
$filetype == ".gif")  $image = @imagecreatefromgif($imagesource);  
if(
$filetype == ".jpg")  $image = @imagecreatefromjpeg($imagesource);  
if(
$filetype == ".png")  $image = @imagecreatefrompng($imagesource);  
if (!
$image) die(); 
$watermark = @imagecreatefrompng('http://www.miweb.com/logo.png'); 
$imagewidth imagesx($image); 
$imageheight imagesy($image);  
$watermarkwidth =  imagesx($watermark); 
$watermarkheight =  imagesy($watermark); 
$startwidth = (($imagewidth $watermarkwidth)/2); 
$startheight = (($imageheight $watermarkheight)/2); 
imagecopy($image$watermark,  $startwidth$startheight00$watermarkwidth$watermarkheight); 
imagejpeg($image); 
imagedestroy($image); 
imagedestroy($watermark); 

Última edición por AJVEvoluzione; 07/06/2007 a las 19:37
  #2 (permalink)  
Antiguo 14/10/2010, 16:15
 
Fecha de Ingreso: julio-2009
Mensajes: 44
Antigüedad: 14 años, 8 meses
Puntos: 0
Respuesta: Cómo incorporar este sello de agua ??

para esto hace falta la libreria GD?
  #3 (permalink)  
Antiguo 15/10/2010, 05:08
 
Fecha de Ingreso: agosto-2010
Ubicación: Tenerife
Mensajes: 893
Antigüedad: 13 años, 8 meses
Puntos: 202
Respuesta: Cómo incorporar este sello de agua ??

Hola. Tienes muchísimo código innecesario.
¿¿ Una función para saber la extensión de un archivo usando $_FILE ??
Si ya existe $_FILES['image']['type']

Pasas la extensión a minúsculas y en el if compruebas si está en mayúsculas... ??¿?¿
...Y así un montón de cosas que sobran.

Así a simple vista lo que no veo son los headers.

No voy a ponerte el ejemplo de golpe habiendo tanto en internet sobre el tema pero yo no me complicaría validando el archivo después del submit.

Código PHP:
<?php
if(isset($_POST['Submit']))
{
    
$image=$_FILES['image']['name'];
    
    if (
$image
    {
        
$extension substr($_FILES['image']['type'], -33);
    
        if (
$extension != "jpg" and $extension != "gif" and $extension != "png" 
            echo 
'<h1>Solo se pueden subir archivos .JPG .GIF o .PNG </h1>';
        else
        {
            
//crear imagen
        
}
    }
}

?>

<form name="newad" method="post" enctype="multipart/form-data" action="">
<input type="file" name="image" >
<input name="Submit" type="submit" value="Subir"> 
</form>


Google !!! No lo he probado, pero es que hay miles de ejemplos en internet.
http://www.martiniglesias.eu/blog/ma...agua-en-php/37
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 06:05.