Redimensionando imagens com PHP
Publicado por Evaldo Barbosa 05/02/2009
[ Hits: 7.722 ]
Homepage: Em breve
Download redimensionar_imagens.php
Esta função é parte integrante de uma classe que criei para manipulação de arquivos de imagem, por isso os "$this". Você pode pegar e construir a sua classe a partir disso.
/** * Cria uma miniatura a partir de uma imagem existente * * @param String $image_file * @param String $type * @param Integer $width * @param Integer $height */ function resize($filename,$type="image/jpeg",$width=0,$height=0) { if (!file_exists($filename)) { $this->notFound(); } //echo $filename; //die(); $this->width = ($width > 0) ? $width : $this->width; $this->height = ($height > 0) ? $height : $this->height; header("Content-type: " . $type); $dim = $this->getDimensions($filename); list($old_width, $old_height) = getimagesize($filename); $image_p = imagecreatetruecolor($dim["w"], $dim["h"]); switch ($type) { case "image/jpeg" : $image = imagecreatefromjpeg($filename); break; case "image/gif" : $image = imagecreatefromgif($filename); break; case "image/png" : $image = imagecreatefrompng($filename); break; default : $image = imagecreatefromjpeg($filename); break; } imagecopyresampled($image_p, $image, 0, 0, 0, 0, $dim["w"], $dim["h"], $old_width, $old_height); switch ($type) { case "image/jpeg" : imagejpeg($image_p, null, $this->jpeg_quality); break; case "image/gif" : imagegif($image_p, null); break; case "image/png" : imagepng($image_p, null); break; default : imagejpeg($image_p, null, $this->jpeg_quality); break; } imagedestroy($image_p); }
Instalar e Configurar o Slackware Linux em 2025
Como configurar os repositórios do apt no Debian 12 em 2025
Passkeys: A Evolução da Autenticação Digital
Instalação de distro Linux em computadores, netbooks, etc, em rede com o Clonezilla
Configurando o Conky para iniciar corretamente no sistema
3 configurações básicas que podem melhorar muito a sua edição pelo editor nano
Como colorir os logs do terminal com ccze
Instalação Microsoft Edge no Linux Mint 22
Como configurar posicionamento e movimento de janelas no Lubuntu (Openbox) com atalhos de teclado
IMPOSSÍVEL CORRIGIR PROBLEMAS, VOCÊ MANTEVE (HOLD) PACOTES QUEBRADOS. (0)
Linux Mint não conecta Wi-Fi sem fio (18)
Backup de arquivos no Mint [RESOLVIDO] (4)
Por que programação de baixo nível e tão comum no Linux do que no wind... (3)