Ir para conteúdo

POWERED BY:

Arquivado

Este tópico foi arquivado e está fechado para novas respostas.

Jardel Pavan Bazi

[RESOLVIDO] Gerar miniaturas sem UPLOAD

Recommended Posts

Boa Tarde alguem poderias me dar uma ajudinha? Estou criando um sistema de fotos no qual preciso que gere uma miniatura sem ter que fazer elas no fireworks. Hoje ele ja busca as imagnes de um determinado diretorio... ae precisava que ele reduzi-se a qualidade e diminui-se o tamanho da mesma... sem criar a mini. segue abaixo o codigo no qual faz a leitura do diretorio. $pasta = $row_RsFotos['pasta']; $diretorio = "/home/meusite/public_html/site/album_fotos/$pasta"; $ponteiro = opendir($diretorio); // monta os vetores com os itens encontrados na pasta while ($nome_itens = readdir($ponteiro)) { $itens[] = $nome_itens; } // ordena o vetor de itens sort($itens); // percorre o vetor para fazer a separacao entre arquivos e pastas foreach ($itens as $listar) { // retira "./" e "../" para que retorne apenas pastas e arquivos if ($listar!="." && $listar!=".."){ $arquivos[]=$listar; } } // lista os arquivos se houverem if ($arquivos != "") { foreach($arquivos as $listar){ print " <a href='album_fotos/$pasta/$listar'> <img border='0' src='album_fotos/$pasta/$listar'></a>"; } } ?> --- Ou seja ele ira lista a foto na variavel $listar.como faço para antes que ele imprima a variavel ele diminua para uma mini 75 x 55 ?Poderias me dar uma mão?

Compartilhar este post


Link para o post
Compartilhar em outros sites

Dá uma estudada no codigo abaixo que eu desenvolvi e utilizo em todos os meus projetos.eu gravei como mini.php e a chamada é feita da seguinte forma:<img src='mini.php?img=url_da_imagem&wh=100' border=0>isso quer dizer para o script que pegue a imagem em url_da_imagem, redimensione no maximo a largura em 100px, caso a altura seja superior a 100, redimensione pela altura no maximo 100px.A rotina não funciona para gif ou png transparente, a imagem volta com fundo preto, isso eu nunca consegui resolver.

<?/* ********************************* responsavel por gerar miniaturas Se Width passado, despreza o height pois calcula automaticamente. se Height passado despreza o width pois calcula automaticamente para manter a proporção da imagem. ex.: width original da imagem = 250px height original da imagem =120px cálculo para o create e copy: enviado: width=200 height = (int)200/250*120=96 enviado: height=100 width = (int)100/120*250=208 ***********************************/function checkgd() { $gd2=""; ob_start(); phpinfo(8); $phpinfo=ob_get_contents(); ob_end_clean(); $phpinfo=strip_tags($phpinfo); $phpinfo=stristr($phpinfo,"gd version"); $phpinfo=stristr($phpinfo,"version"); preg_match('/\d/',$phpinfo,$gd); if ($gd[0]=='2') { $gd2="yes"; } return $gd2; }function createthumb($name,$new_w,$new_h) { global $gd2; $system=explode(".",basename($name)); if (preg_match("/jpg|jpeg/",$system[1])) { $src_img=imagecreatefromjpeg($name); } if (preg_match("/png/",$system[1])) { $src_img=imagecreatefrompng($name); } if (preg_match("/gif/",$system[1])) { $src_img=imagecreatefromgif($name); } $old_x=imageSX($src_img); $old_y=imageSY($src_img); if ($old_x > $old_y) { $thumb_w=$new_w; $thumb_h=$old_y*($new_h/$old_x); } if ($old_x < $old_y) { $thumb_w=$old_x*($new_w/$old_y); $thumb_h=$new_h; } if ($old_x == $old_y) { $thumb_w=$new_w; $thumb_h=$new_h; } if ($gd2=="") { $dst_img=ImageCreate($thumb_w,$thumb_h); imagecopyresized($dst_img,$src_img,0,0,0,0,$thumb_w,$thumb_h,$old_x,$old_y); } else { $dst_img=ImageCreateTrueColor($thumb_w,$thumb_h); imagecopyresampled($dst_img,$src_img,0,0,0,0,$thumb_w,$thumb_h,$old_x,$old_y); } if (preg_match("/png/",$system[1])) imagepng($dst_img); elseif (preg_match("/gif/",$system[1])) imageGif($dst_img); else imagejpeg($dst_img); imagedestroy($dst_img); imagedestroy($src_img); }$gd2=checkgd() or die("erro no GD");createthumb($_GET["img"],$_GET["wh"],$_GET["wh"]);?>

Compartilhar este post


Link para o post
Compartilhar em outros sites

Opa... waleu amigoooobrigado.... funcioouuuu...

Dá uma estudada no codigo abaixo que eu desenvolvi e utilizo em todos os meus projetos.eu gravei como mini.php e a chamada é feita da seguinte forma:<img src='mini.php?img=url_da_imagem&wh=100' border=0>isso quer dizer para o script que pegue a imagem em url_da_imagem, redimensione no maximo a largura em 100px, caso a altura seja superior a 100, redimensione pela altura no maximo 100px.A rotina não funciona para gif ou png transparente, a imagem volta com fundo preto, isso eu nunca consegui resolver.

<?/* ********************************* responsavel por gerar miniaturas Se Width passado, despreza o height pois calcula automaticamente. se Height passado despreza o width pois calcula automaticamente para manter a proporção da imagem. ex.: width original da imagem = 250px height original da imagem =120px cálculo para o create e copy: enviado: width=200 height = (int)200/250*120=96 enviado: height=100 width = (int)100/120*250=208 ***********************************/function checkgd() { $gd2=""; ob_start(); phpinfo(8); $phpinfo=ob_get_contents(); ob_end_clean(); $phpinfo=strip_tags($phpinfo); $phpinfo=stristr($phpinfo,"gd version"); $phpinfo=stristr($phpinfo,"version"); preg_match('/\d/',$phpinfo,$gd); if ($gd[0]=='2') { $gd2="yes"; } return $gd2; }function createthumb($name,$new_w,$new_h) { global $gd2; $system=explode(".",basename($name)); if (preg_match("/jpg|jpeg/",$system[1])) { $src_img=imagecreatefromjpeg($name); } if (preg_match("/png/",$system[1])) { $src_img=imagecreatefrompng($name); } if (preg_match("/gif/",$system[1])) { $src_img=imagecreatefromgif($name); } $old_x=imageSX($src_img); $old_y=imageSY($src_img); if ($old_x > $old_y) { $thumb_w=$new_w; $thumb_h=$old_y*($new_h/$old_x); } if ($old_x < $old_y) { $thumb_w=$old_x*($new_w/$old_y); $thumb_h=$new_h; } if ($old_x == $old_y) { $thumb_w=$new_w; $thumb_h=$new_h; } if ($gd2=="") { $dst_img=ImageCreate($thumb_w,$thumb_h); imagecopyresized($dst_img,$src_img,0,0,0,0,$thumb_w,$thumb_h,$old_x,$old_y); } else { $dst_img=ImageCreateTrueColor($thumb_w,$thumb_h); imagecopyresampled($dst_img,$src_img,0,0,0,0,$thumb_w,$thumb_h,$old_x,$old_y); } if (preg_match("/png/",$system[1])) imagepng($dst_img); elseif (preg_match("/gif/",$system[1])) imageGif($dst_img); else imagejpeg($dst_img); imagedestroy($dst_img); imagedestroy($src_img); }$gd2=checkgd() or die("erro no GD");createthumb($_GET["img"],$_GET["wh"],$_GET["wh"]);?>

Compartilhar este post


Link para o post
Compartilhar em outros sites

×

Informação importante

Ao usar o fórum, você concorda com nossos Termos e condições.