Foros del Web » Programando para Internet » PHP »

Ayudita con la funcion de las imagenes cortadas

Estas en el tema de Ayudita con la funcion de las imagenes cortadas en el foro de PHP en Foros del Web. Este es el codigo Codigo PHP Muestra la imagen en miniatura <div class='galeria' style="text-align: center; padding: 10px 10px 10px 10px;"><?php for($a=2; $a<=10; $a++) { if(file_exists($_SERVER[DOCUMENT_ROOT] ...
  #1 (permalink)  
Antiguo 25/03/2011, 10:27
 
Fecha de Ingreso: febrero-2007
Ubicación: Caracas
Mensajes: 148
Antigüedad: 17 años, 1 mes
Puntos: 6
Ayudita con la funcion de las imagenes cortadas

Este es el codigo


Codigo PHP
Muestra la imagen en miniatura

<div class='galeria' style="text-align: center; padding: 10px 10px 10px 10px;"><?php for($a=2; $a<=10; $a++) { if(file_exists($_SERVER[DOCUMENT_ROOT] . "/proyectocrossh/img/productos/" . $a . "-" . $data_id . ".jpg")) { if((!(file_exists($_SERVER[DOCUMENT_ROOT] . "/proyectocrossh/img/productos/t-" . $a . "-" . $data_id . ".jpg"))) OR (filemtime($_SERVER[DOCUMENT_ROOT] . "/proyectocrossh/img/productos/2-" . $a . "-" . $data_id . ".jpg")<($timestamp-18000))) { @cropImage(100, 111,$_SERVER[DOCUMENT_ROOT] . "/proyectocrossh/img/productos/" . $a . "-" . $data_id . ".jpg", "jpg",$_SERVER[DOCUMENT_ROOT] . "/proyectocrossh/img/productos/2-" . $a . "-" . $data_id . ".jpg"); } echo "<a href='/proyectocrossh/img/productos/" . $a . "-" . $data_id . ".jpg' title='" . $data_titulo . "' class='cpModal' rel='galeria'><img src='/proyectocrossh/img/productos/2-" . $a . "-" . $data_id . ".jpg' alt='" . $data_titulo . "' border='0' vspace='3' hspace='3' /></a>"; } } ?></div>

Funcion de Imagen miniatura corta, pega y guarda

----------------------------------------------------------------------------------------------------------------------------------------------------------------------
function cropImage($nw, $nh, $source, $stype, $dest) { $size = getimagesize($source); $w = $size[0]; $h = $size[0]; switch($stype) { case 'gif': $simg = imagecreatefromgif($source); break; case 'jpg': $simg = imagecreatefromjpeg($source); break; case 'png': $simg = imagecreatefrompng($source); break; } $dimg = imagecreatetruecolor($nw, $nh); $wm = $w/$nw; $hm = $h/$nh; $h_height = $nh/2; $w_height = $nw/2; if($w> $h) { $adjusted_width = $w / $hm; $half_width = $adjusted_width /2; $int_width = $half_width - $w_height; imagecopyresampled($dimg,$simg,-$int_width,0,0,0,$adjusted_width,$nh,$w,$h); } elseif(($w <$h) || ($w == $h)) { $adjusted_height = $h / $wm; $half_height = $adjusted_height / 2; $int_height = $half_height - $h_height; imagecopyresampled($dimg,$simg,0,-$int_height,0,0,$nw,$adjusted_height,$w,$h); } else { imagecopyresampled($dimg,$simg,0,0,0,0,$nw,$nh,$w, $h); } imagejpeg($dimg,$dest,100); } ?>


------------------------------------------------------------------------------------------------------------------------------------

Nota: al nombrar las variables de la imagen iniciando en 0, me ajusta la imagen, pero lo que quiero es ajustarla al recuadro, para que no salga negro en los espacios.Ahhhhh Auxilio >:(
  #2 (permalink)  
Antiguo 25/03/2011, 10:32
Avatar de maycolalvarez
Colaborador
 
Fecha de Ingreso: julio-2008
Ubicación: Caracas
Mensajes: 12.120
Antigüedad: 15 años, 8 meses
Puntos: 1532
Respuesta: Ayudita con la funcion de las imagenes cortadas

dios!!! organiza el código please!!!, así dudo mucho que alguien te ayude
__________________
¡Por favor!: usa el highlight para mostrar código
El que busca, encuentra...
  #3 (permalink)  
Antiguo 25/03/2011, 10:43
 
Fecha de Ingreso: febrero-2007
Ubicación: Caracas
Mensajes: 148
Antigüedad: 17 años, 1 mes
Puntos: 6
Respuesta: Ayudita con la funcion de las imagenes cortadas

Código:
 	function cropImage($nw, $nh, $source, $stype, $dest) {

	   $size = getimagesize($source);
	   $w = $size[0];
	   $h = $size[0];
	
	   switch($stype) {
	       case 'gif':
	       $simg = imagecreatefromgif($source);
	       break;
	       case 'jpg':
	       $simg = imagecreatefromjpeg($source);
	       break;
	       case 'png':
	       $simg = imagecreatefrompng($source);
	       break;
	   }
	
	   $dimg = imagecreatetruecolor($nw, $nh);
	
	   $wm = $w/$nw;
	   $hm = $h/$nh;
	
	   $h_height = $nh/2;
	   $w_height = $nw/2;
	
	   if($w> $h) {
	
	       $adjusted_width = $w / $hm;
	       $half_width = $adjusted_width /2;
	       $int_width = $half_width - $w_height;
	
	       imagecopyresampled($dimg,$simg,-$int_width,0,0,0,$adjusted_width,$nh,$w,$h);
	
	   } elseif(($w <$h) || ($w == $h)) {
	
	       $adjusted_height = $h / $wm;
	       $half_height = $adjusted_height / 2;
	       $int_height = $half_height - $h_height;
	
	       imagecopyresampled($dimg,$simg,0,-$int_height,0,0,$nw,$adjusted_height,$w,$h);
	
	   } else {
	       imagecopyresampled($dimg,$simg,0,0,0,0,$nw,$nh,$w,$h);
	   }
	
	   imagejpeg($dimg,$dest,100);

	}		 
	
?>
PHP

Código:
<table width='700' cellpadding='0' cellspacing='0'>
<tr valign='top'><td width='350' align='center'><?php

	if(file_exists($_SERVER[DOCUMENT_ROOT] . "/proyectocrossh/img/productos/1-" . $data_id . ".jpg")) {

	
		echo "<a href='/proyectocrossh/img/productos/1-" . $data_id . ".jpg' title='" . $data_titulo  . "' class='cpModal' rel='galeria'><img src='/proyectocrossh/img/productos/1-" . $data_id . ".jpg' alt='" . $data_titulo . "' border='0' width='350' height='350' /></a>";
		
	}
	else
	{
		echo "<img src='/proyectocrossh/img/trans.gif' alt='" . $data_titulo . "' border='0' width='350' height='300' />";
	}
	
?></td><td><div class='descripcion'>
<h1><?php echo ucwords(strtolower($data_titulo)) ; ?></h1>
<h2>Nº Referencia: <?php echo $data_referencia; ?></h2>
<p><?php echo $data_interna; ?></p>
<h3>Precio: <?php /*?><?php echo money_format('%.2n', $data_precio); ?><?php */?></h3>
</div>
<div class='galeria' style="text-align: center; padding: 10px 10px 10px 10px;">

<?php

	for($a=2; $a<=10; $a++) {
	
		if(file_exists($_SERVER[DOCUMENT_ROOT] . "/proyectocrossh/img/productos/" . $a . "-" . $data_id . ".jpg")) {

			if((!(file_exists($_SERVER[DOCUMENT_ROOT] . "/proyectocrossh/img/productos/t-" . $a . "-" . $data_id . ".jpg"))) OR (filemtime($_SERVER[DOCUMENT_ROOT] . "/proyectocrossh/img/productos/t-" . $a . "-" . $data_id . ".jpg")<($timestamp-18000)))  {

				@cropImage(100, 111,$_SERVER[DOCUMENT_ROOT] . "/proyectocrossh/img/productos/" . $a . "-" . $data_id . ".jpg", "jpg",$_SERVER[DOCUMENT_ROOT] . "/proyectocrossh/img/productos/t-" . $a . "-" . $data_id . ".jpg");

			}		

			echo "<a href='/proyectocrossh/img/productos/" . $a . "-" . $data_id . ".jpg' title='" . $data_titulo  . "' class='cpModal' rel='galeria'><img src='/proyectocrossh/img/productos/t-" . $a . "-" . $data_id . ".jpg' alt='" . $data_titulo . "' border='0' vspace='3' hspace='3'  /></a>";
			
		}
	
	}
	
?>

</div>



</td></tr></table></div>

Etiquetas: cortadas, funcion, imagenes
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 20:02.