query($sql); //if($row=mysql_fetch_array($result)){ if($row=mysqli_fetch_array($result)){ $tipo = $row["formato"]; $imagen = $row["info"]; }else{ die ("No disponible"); //header('location:index.php'); } } else{ die ("No disponible"); //header('location:index.php'); } if(empty($ancho)){ header('Content-type: '.$tipo.''); echo $imagen; die(); } //}else{ // $sql = "SELECT info, formato FROM foto WHERE idPersona =" . $_GET['idpersona'] . " ORDER BY fechaPublicacion"; //} //echo $sql; header('Content-type: '.$tipo.''); // Generar el thumbnail: // Se crea la imagen desde el campo binario de la BD $img = imagecreatefromstring($imagen); // Tamaño del Thumbanil (de la imagen a generar ..) if($ancho != "" && $ancho != 0) $picsize = $ancho; else $picsize = 80; // Se obtienen los datos del ancho y alto de la imagen. $new_w = imagesx($img); $new_h = imagesy($img); if($new_w > $picsize || $new_h > $picsize){ if($new_h > $new_w){ // Se calcula la relación alto/ancho $aspect_ratio = $new_w / $new_h; // Se ajusta al nuevo tamaño $new_h = $picsize; $new_w = abs($new_h * $aspect_ratio); }else{ $aspect_ratio = $new_h / $new_w; // Se ajusta al nuevo tamaño $new_w = $picsize; $new_h = abs($new_w * $aspect_ratio); } }else{ header('Content-type: '.$tipo.''); echo $imagen; die(); } // Se crea la mascara de la imagen nueva //$dst_img = imagecreate($new_w,$new_h); //ver. 1.x $dst_img = ImageCreateTrueColor($new_w,$new_h); // ver. 2.x // Se copia y reajusta el nuevo tamaño en la nueva imagen. //imagecopyresized($dst_img,$img,0,0,0,0,$new_w,$new_h,imagesx($img),imagesy($img)); // ver. 1.x imagecopyresampled($dst_img,$img,0,0,0,0,$new_w,$new_h,imagesx($img),imagesy($img)); // ver. 2.x // Se entrega al buffer de salida (navegador en este caso) la imagen en formato JPEG // El tercer parámetro (100) indica la calidad de la imagen: en porcentaje relación calidad/peso imagen. imagejpeg($dst_img,'',100); //echo $imagen; ?>