0 && $height >0){ #Estan definidos el ancho y el alto, por lo que se toman ambos $twidth = $width; $theight = $height; } else if ($width > 0 && $height ==0){ #Esta definido solo el ancho, por lo que se calcula el alto proporcional a la imagen original $origWidth = imagesx($pic); $origHeight = imagesy($pic); $twidth = $width; # Ancho $theight = $twidth * ($origHeight/$origWidth); # Alto } else if ($width == 0 && $height >0){ #Esta definido solo el alto, por lo que se calcula el ancho proporcional a la imagen original $origWidth = imagesx($pic); $origHeight = imagesy($pic); $theight = $height; # Alto $twidth = $theight * ($origWidth/$origHeight); # Ancho }else { #Ambos parametros en cero, se deja la imagen de tamaņo original $origWidth = imagesx($pic); $origHeight = imagesy($pic); $twidth = $origWidth; $theight = $origHeight; } #Se calcula el nombre de la imagen a crear $newNameStem = trim($newNameStem); if ($newNameStem != ""){ $newBaseFileName = $newNameStem."_". $originalBaseFileName . "_". $twidth . "x" . $theight . "q".$quality;; } else{ $newBaseFileName = $originalBaseFileName . "_". $twidth . "x" . $theight . "q".$quality; } $newFileName = $newBaseFileName . "." . $originalExtFileName; $newFilePath = $picsBasePath . $newFileName; if (!file_exists($newFilePath)){ #Se crea la imagen nueva, en el archivo de nombre calculado, con los parametros dados $thumb = @imagecreatetruecolor ($twidth, $theight) or die ("No se puede crear la imagen de tamaño: ".$theight ."x". $twidth); imagecopyresized($thumb, $pic, 0, 0, 0, 0,$twidth, $theight, $origWidth, $origHeight); ImageJPEG($thumb,$newFilePath,$quality); # Thumb } } $resultBundle= array("fileName"=>$newFileName, "height" => $theight, "width"=>$width,"quality"=>$quality,"baseName"=>$originalBaseFileName); imagedestroy($pic); imagedestroy($thumb); return $resultBundle; } function LoadJpeg($imgname) { $im = @imagecreatefromjpeg($imgname); /* Attempt to open */ if (!$im) { /* See if it failed */ $im = imagecreate(150, 30); /* Create a blank image */ $bgc = imagecolorallocate($im, 255, 255, 255); $tc = imagecolorallocate($im, 0, 0, 0); imagefilledrectangle($im, 0, 0, 150, 30, $bgc); /* Output an errmsg */ imagestring($im, 1, 5, 5, "Error cargando $imgname", $tc); } return $im; } ?>