Redimensionando imagens com PHP
Publicado por Evaldo Barbosa 05/02/2009
[ Hits: 7.621 ]
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); }
Contador de acessos com Oracle
Script PHP simples que mostra IP e UserAgent do visitante, mesmo em alguns casos de proxy
Atenção a quem posta conteúdo de dicas, scripts e tal (6)
Como Configurar um Túnel SSH Reverso para Acessar Sua Máquina Local a Partir de uma Máquina Remota
Configuração para desligamento automatizado de Computadores em um Ambiente Comercial
O mínimo que você precisa saber sobre o terminal (parte 2)
O mínimo que você precisa saber sobre o terminal (parte 1)
Como iniciar uma máquina virtual do VirtualBox automaticamente no boot do LUbuntu 18 LTS
Mudar o gerenciador de login (GDM para SDDM e vice-versa) - parte 2
Como deixar as abas do Firefox mais fininhas
Mudar o gerenciador de login (GDM para SDDM)
"Tentando" fazer com que programas rodem no Wayland e no X11
Como baixar os drivers de áudio no linux mint? (7)
Como posso localizar o arquivo HTML da página inicial do GLPI dentro d... (2)
[Python] Automação de scan de vulnerabilidades
[Python] Script para analise de superficie de ataque
[Shell Script] Novo script para redimensionar, rotacionar, converter e espelhar arquivos de imagem
[Shell Script] Iniciador de DOOM (DSDA-DOOM, Doom Retro ou Woof!)
[Shell Script] Script para adicionar bordas às imagens de uma pasta