Ver Mensaje Individual
  #4 (permalink)  
Antiguo 09/12/2011, 13:46
Avatar de jolie_girl
jolie_girl
 
Fecha de Ingreso: agosto-2008
Ubicación: mexico
Mensajes: 346
Antigüedad: 15 años, 8 meses
Puntos: 10
Respuesta: detectar ancho de imagen

Te voy a pasar una funcion que hice , foros del web me ha ayudado a mi mucho

<?php function createThumbs( $pathToImages, $pathToThumbs, $thumbWidth, $fname )
{
// open the directory
$dir = opendir( $pathToImages );

// loop through it, looking for any/all JPG files:
// while (false !== ($fname = readdir( $dir ))) {
// parse path for the extension
$info = pathinfo($pathToImages . $fname);
// continue only if this is a JPEG image
if ( strtolower($info['extension']) == 'jpg' )
{
//echo "Imagen guardada con exito {$fname} <br />";

// load image and get image size
$img = imagecreatefromjpeg( "{$pathToImages}{$fname}" );

$rutadeimg=$pathToImages.$fname;

$img_info = getimagesize($rutadeimg); //Tu imagen

$a=$img_info[0];
$b=$img_info[1];

$proporcion=$a/$b;

$x=$thumbWidth;
$y=$thumbWidth;

if($proporcion<1)
{
if($b>$y){
$newa = floor( $a * ( $y/ $b ) );
$newb=$y;
}else{

//Deja tamaño original para que no se vea pixelado
$newa=$a;
$newb=$b;


}


}else{

if($a>$x){
$newb = floor( $b * ( $x/ $a ) );
$newa=$x;
}else{
//Deja tamaño original para que no se vea pixelado
$newa=$a;
$newb=$b;
}



}



// create a new tempopary image
$tmp_img = imagecreatetruecolor( $newa, $newb );

// copy and resize old image into new image
imagecopyresized( $tmp_img, $img, 0, 0, 0, 0, $newa, $newb, $a, $b );

//imagettftext($tmp_img,5,0,0,"aca estaria el texto",$black);
//$white = imagecolorallocate($tmp_img, 255,255,255);
//imagettftext($tmp_img, '7', 0, 8, 68, $white, "arial.ttf", "RematoMisCosas.com");

// save thumbnail into a file
imagejpeg( $tmp_img, "{$pathToThumbs}{$fname}" );
}





//}
// close the directory
closedir( $dir );
}
?>
__________________
Solicito colaboradoras para proyecto social media largo plazo. Manda mp