Noticias Weblogs Foros Wiki Código

RecorteX

394 usuarios y 230 recortes de código
Usuario

Contraseña
Crear cuenta
asp csharp css fechas fichero Flash html imagenes java javascript linux mysql oracle php sql SQLServer url vbnet xhtml xml
Top Usuarios
fjmp76 (35)
albin (31)
juanjo (29)
josuebasurto (28)
pedrocaro (9)
stanz (8)
AndiXTRM (7)
Joserra (7)
miiglesi (6)
aplyca (5)
Top Etiquetas
php (38)
vbnet (27)
javascript (26)
html (25)
java (22)
sql (16)
csharp (16)
xml (13)
mysql (13)
css (10)
xhtml (7)
Flash (7)
imagenes (7)
linux (6)
asp (6)
fechas (6)
SQLServer (5)
oracle (5)
url (4)
fichero (4)

Escalado de una imagen forzando ancho y alto sin deformarla

Escala una imágen al máximo ancho o al máximo alto, según sea su proporción y la proporción deseada, y coge la parte central del resultado garantizando la proporcion deseada.

Dicese, de una imagen de 1600 x 1200, si se solicita 350x300, la escalará a 400x300 y cogerá de 25,0 a 375,300 garantizando un escalado sin distorsión, y las medidas deseadas.

function clipImage($file, $width, $height) {
	$imSrc  = imagecreatefromjpeg($file);
	$w      = imagesx($imSrc);
	$h      = imagesy($imSrc);
	if($width/$height>$w/$h) {
		$nh = ($h/$w)*$width;
		$nw = $width;
	} else {
		$nw = ($w/$h)*$height;
		$nh = $height;
	}
	$dx = ($width/2)-($nw/2);
	$dy = ($height/2)-($nh/2);
	$imTrg  = imageCreateTrueColor($width, $height);
	imagecopyresized($imTrg, $imSrc, $dx, $dy, 0, 0, $nw, $nh, $w, $h);
	imagedestroy($imSrc);
	imagejpeg($imTrg, $file, 95);
	imagedestroy($imTrg);
}
Identifícate para dejar un comentario.
info@recortex.com - Proyecto: Juanjo Navarro, 2006 - Diseño: Albin - Información legal y técnica