function reduz_imagem($img, $max_x, $max_y, $nome_foto) { list($width, $height) = getimagesize($img); $original_x = $width; $original_y = $height; if($original_x > $original_y) { $porcentagem = (100 * $max_x) / $original_x; } else { $porcentagem = (100 * $max_y) / $original_y; } $tamanho_x = $original_x * ($porcentagem / 100); $tamanho_y = $original_y * ($porcentagem / 100); $image_p = imagecreatetruecolor($tamanho_x, $tamanho_y); $image = imagecreatefromjpeg($img); imagecopyresampled($image_p, $image, 0, 0, 0, 0, $tamanho_x, $tamanho_y, $width, $height); return imagejpeg($image_p, $nome_foto, 80); } function Verifica_Upload() { $this->imagem = isset($_FILES['imagem']) ? $_FILES['imagem'] : FALSE; $get = getimagesize($this->arquivo['tmp_name']); if($get["mime"] != "image/jpeg") { echo "<span style=\"color: white; border: solid 1px; background: red;\">Esse foto nao é uma imagem valida</span>"; exit; } return true; } function Envia_Arquivo() { if($this->Verifica_Upload()) { $this->gera_fotos(); return true; } else { echo "<span style=\"color: white; border: solid 1px; background: red;\">".$this->erro[$this->arquivo['error']]."</span>"; } } function gera_fotos() { $diretorio = "../../novidades/"; $nome_foto = "imagem_".time().".jpg"; $this->reduz_imagem($this->arquivo['tmp_name'], 280, 600, $diretorio.$nome_foto); $data = date("Y-m-d"); $titulo_br = $_POST['titulo']; $descricao_br = $_POST['descricao']; $query="insert into tabela(id,data,titulo,descricao,imagem) values('','$data','$titulo_br','$titulo_en','$descricao_br','$descricao_en','$nome_foto')"; $res = parent::gravar($query); return $res; }
a questao é que agora.. eu to querendo fazer ele multiplo, tipo, os arquivos vem de um array:
como exemplo segue o array, com upload de 3 fotos (esta array podera ser infinta)
Array( [imagem] => Array ( [name] => Array ( [0] => dolls_complete_set___full_view.png [1] => Urban_Text.jpg [2] => imagem3.jpg ) [type] => Array ( [0] => image/png [1] => image/jpeg [2] => image/jpeg ) [tmp_name] => Array ( [0] => C:\WINDOWS\TEMP\php5A.tmp [1] => C:\WINDOWS\TEMP\php5B.tmp [2] => C:\WINDOWS\TEMP\php5C.tmp ) [error] => Array ( [0] => 0 [1] => 0 [2] => 0 ) [size] => Array ( [0] => 612395 [1] => 471877 [2] => 23877 ) ))
entao eu teria que fazer o mesmo sistema, soh que usando um sizeof para ele ir repetindo a ação de reduzir e gerar o thumbnail...
soh que nao conseguie fazer funcionar, alguem ja fez algo parecido que possa me ajudar?
resolvi o meu problema
function reduz_imagem($img, $max_x, $max_y, $nome_foto) { list($width, $height) = getimagesize($img); $original_x = $width; $original_y = $height; if($original_x > $original_y) { $porcentagem = (100 * $max_x) / $original_x; } else { $porcentagem = (100 * $max_y) / $original_y; } $tamanho_x = $original_x * ($porcentagem / 100); $tamanho_y = $original_y * ($porcentagem / 100); $image_p = imagecreatetruecolor($tamanho_x, $tamanho_y); $image = imagecreatefromjpeg($img); imagecopyresampled($image_p, $image, 0, 0, 0, 0, $tamanho_x, $tamanho_y, $width, $height); return imagejpeg($image_p, $nome_foto, 80); } function envia_Foto() { if($this->gera_fotos()) { return true; } else { echo "<span style=\"color: white; border: solid 1px; background: red;\">".$this->erro[$this->arquivo['error']]."</span>"; } } function gera_fotos() { $diretorio = "../../imagens_artigos/"; for($i = 0; $i < sizeof($_FILES['imagem']['name']); $i++) { $nome_foto = "imagem_".time().$i.".jpg"; $this->reduz_imagem($_FILES['imagem']['tmp_name'][$i], 280, 600, $diretorio.$nome_foto); $data = date("Y-m-d"); $titulo_br = $_POST['titulo']; $descricao_br = $_POST['descricao']; $query="insert into tabela(id,data,titulo,descricao,imagem) values('','$data','$titulo_br','$titulo_en','$descricao_br','$descricao_en','$nome_foto')"; $res = parent::gravar($query); } return $res; }
agora falta fazer um verificador

Edição feita por: boirock, 10/10/2007, 21:28.
E dizem que no oitavo dia Deus criou o [codebox]