View: Thumbnail de tus fotografias con PHP (2)

  1. 10 months ago by jacinmontava
    1. <?php
    2.  
    3. // Variables que indican el archivo de la imagen y el nuevo tamano
    4. $filename = "./imagenes/11974726662819-2.jpg";
    5.  
    6. // Content-type para el navegador
    7. header('Content-type: image/jpeg');
    8.  
    9. // Se obtienen las nuevas dimensiones
    10. list($width, $height) = getimagesize($filename);
    11. $newwidth = 120; ///forzamos la imagen al tamaƱo deseado
    12. $newheight = floor( $height * (120 / $width ) ); ///la altura la obtenemos proporcionalmente para no deformar la imagen
    13.  
    14.  
    15. // Cargar la imagen
    16. $thumb = imagecreate($newwidth, $newheight);
    17. $source = imagecreatefromjpeg($filename);
    18.  
    19. // Redimensionar
    20. imagecopyresized($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
    21.  
    22. // Mostrar la nueva imagen
    23. imagejpeg($thumb);
    24.  
    25. ?>

0 comment about "Thumbnail de tus fotografias con PHP (2)"