Manual de PHP: Imágenes

Imágenes

La librería GD de PHP permite crear y manipular imágenes en numerosos formatos, incluyendo GIF, PNG, JPEG y XPM.

Recursos

Veamos un ejemplo de cómo trabajar con imágenes con PHP.

<?php
//descargar foto de Internet al disco duro
$foto_web = "http://www.domain.com/images/foto.jpg";
$foto = "dowloads/images/foto.jpg";
copy($foto_web, $foto);
 
//normalizar foto a 640 pixels, calidad 82%
$image = imagecreatefromstring(file_get_contents($foto));
$width = imagesx($image);
$height = imagesy($image);
if ($width > 640) {
    $new_width = 640;
} else {
    $new_width = $width;
}
$new_height = $new_width * ($height / $width);
$new_image = imagecreatetruecolor($new_width, $new_height);
imagecopyresampled($new_image, $image, 0, 0, 0, 0,
    $new_width, $new_height, $width, $height);
imagejpeg($new_image, $foto, 82);
imagedestroy($image);
imagedestroy($new_image);
?>

Artículos en la categoría "Manual de PHP"

  1. Manual de PHP: Estructuras de control
  2. Manual de PHP: Funciones
  3. Manual de PHP: Objetos
  4. Manual de PHP: Formularios web
  5. Manual de PHP: Imágenes
  6. Manual de PHP: XML
  7. Manual de PHP: MySQL
  8. Manual de PHP: Sesiones
  9. Manual de PHP: Matrices
  10. Manual de PHP: Expresiones regulares
  11. Manual de PHP: Sanear datos de usuario
  12. Manual de PHP: Email
  13. Manual de PHP: Evitar el hotlinking de los buscadores