sábado, 19 de março de 2011

upload de imagens

function salva_banner($imagem,$pasta,$frase){
error_reporting(E_ALL);

include('class.upload.php');


$handle = new Upload($imagem);
  
$arquivo = isset($imagem) ? $imagem : FALSE;

  
if($arquivo){
$tamanhos = getimagesize($arquivo["tmp_name"]);
  //echo "Aguarde, redimensionando sua imagem ...";
}

  
  
    if ($handle->uploaded) {
      
        // Configuracoes
$handle->file_overwrite = true;
$nome= md5(uniqid(time()));
$handle->file_new_name_body   =  $nome;
$handle->image_ratio = true;
if (($tamanhos[0] > 640) || ($tamanhos[1] > 480)) {

$escala = $tamanhos[0] / $tamanhos[1];

$tamanhow = 640;
$tamanhoh = 480;
$width = $tamanhos[0];
$height = $tamanhos[1];
    
if ($escala < 1.33333333333333333333){
$widthx = $tamanhoh * $escala;
$width = $widthx;
$height = $tamanhoh;
}elseif ($escala > 1.33333333333333333333){
$heightx = $tamanhow / $escala;
$width = $tamanhow;
$height = $heightx;
}else {
$heightx = $tamanhoh / $escala;
$width = $tamanhoh;
$height = $heightx;
}

$handle->image_resize            = true;
$handle->image_x                 = $width;
$handle->image_y = $height;
}
else{
$handle->image_resize            = false;
}




$handle->image_convert = 'jpg';
$handle->jpeg_quality = 60;
$handle->image_text = $frase;//'Teste ...'; //escreve um texto no meio da foto;

        // now, we start the upload 'process'. That is, to copy the uploaded file
        // from its temporary location to the wanted location
        // It could be something like $handle->Process('/home/www/my_uploads/');
        $handle->Process($pasta.'/'); //'fotos/');//pasta aonde vai ser guardado as fotos
     return $pasta.'/'.$nome.'.jpg';
        // we delete the temporary files
        $handle-> Clean();

    }
else {
        // if we're here, the upload file failed for some reasons
        // i.e. the server didn't receive the file
        echo '
';
        echo '
file not uploaded on the server';
        echo '  Error: ' . $handle->error . '';
        echo '
';
}


}

Nenhum comentário:

Postar um comentário