Ir para conteúdo
Fórum Script Brasil
  • 0

Upload E Redimensionamento De Imagem


gustavovalle

Pergunta

Boa tarde pessoal segui a risca toda a documentacao do aspupload e aspjpeg pois para hospedar um site para um cliente no terra so usando esses componentes.

Como funciona, 1 envio o arquivo, isso esta ok depois tranformo a imagem para 3 tamanhos diferentes e posteriormente apagop o arquivo original. Mas não esta havendo o redimensionamento e nem apagando o arquivo original. Ele so manda o mesmo.

Obrigado

Case "INCLUIR_IMAGEM"
'Pega o Caminho da Pasta Imagens
Set rs = Dados_Gerais("")
lc_diretorio = rs("picture")
rs.Close 

Set upl = Server.CreateObject("Persits.Upload")

'upl.Path = lc_diretorio
'==============================================================================
'LIMITA O TAMANHO DO ARQUIVO PARA 500KB
'==============================================================================
upl.SetMaxSize 500000, True

On Error Resume Next

upl.Save lc_diretorio

If Err.Number = 8 Then

                  response.write "<table width=100% height=85 border=0 cellspacing=0 cellpadding=0>"
                  response.write "<td align=center valign=middle class=Nomes_Forms>"
                  response.Write "Esta imagem possui "& FormatNumber(File.OriginalSize,0) &" Kb<BR><BR>"
                  response.Write "O que exede o máximo permitido que é de 500 Kb por imagem<BR><BR>"
                  response.Write "<a href=java script:history.go(-1); class=Nomes_Forms_Normal>"
                  response.Write "&laquo; voltar ao formulário"
                  response.Write "</a>"
                  response.write "</td>" 
                  response.write "</table>"

Else
'==============================================================================

lc_id = upl.form("txt_id")
lc_galeria = upl.form("txt_galeria")
lc_imagem = Trim(upl.form("txt_imagem"))
lc_legenda = Trim(upl.form("txt_legenda"))

link = Mid(lc_imagem, InstrRev(lc_imagem, "\") + 1)
lc_link = Right(link,4)
lc_diahora = day(now) & month(now) & year(now) & hour(now) & minute(now) & second(now)
lc_foto = lc_cliente & lc_id & lc_diahora & lc_link

Rem Redimencionando a Imagem

        Set Jpeg = Server.CreateObject("Persits.Jpeg")
        
        Jpeg.Open (lc_diretorio & link)
        
        if Jpeg.Width > Jpeg.Height then
            intXSize = 90
            intYSize = (intXSize / Jpeg.Width) * Jpeg.Height
        else
            intYSize = 90
            intXSize = (intYSize / Jpeg.Height) * Jpeg.Width
        end if
        
        Jpeg.Width = intXSize
        Jpeg.Height = intYSize
        
        'Jpeg.Sharpen 1, 150
        
        Jpeg.Save lc_diretorio & "P" & lc_foto
        
        Set Jpeg = nothing
        
Rem Redimencionando a Imagem

        Set Jpeg = Server.CreateObject("Persits.Jpeg")
        
        Jpeg.Open (lc_diretorio & link)
        
        if Jpeg.Width > Jpeg.Height then
            intXSize = 170
            intYSize = (intXSize / Jpeg.Width) * Jpeg.Height
        else
            intYSize = 170
            intXSize = (intYSize / Jpeg.Height) * Jpeg.Width
        end if
        
        Jpeg.Width = intXSize
        Jpeg.Height = intYSize
        
        'Jpeg.Sharpen 1, 150
        
        Jpeg.Save lc_diretorio & "M" & lc_foto
        
        Set Jpeg = nothing
        
Rem Redimencionando a Imagem

        Set Jpeg = Server.CreateObject("Persits.Jpeg")
        
        Jpeg.Open (lc_diretorio & link)
        
        if Jpeg.Width > Jpeg.Height then
            intXSize = 449
            intYSize = (intXSize / Jpeg.Width) * Jpeg.Height
        else
            intYSize = 449
            intXSize = (intYSize / Jpeg.Height) * Jpeg.Width
        end if
        
        Jpeg.Width = intXSize
        Jpeg.Height = intYSize
        
        'Jpeg.Sharpen 1, 150
        
        Jpeg.Save lc_diretorio & "G" & lc_foto
        
        Set Jpeg = nothing

upl.Delete
Set upl = Nothing

'Se não existe insere no banco de dados
SQL1 = "INSERT INTO tbl_foto (galeria, imagem, legenda) VALUES ('" & lc_id & "','" & lc_foto & "','" & lc_legenda & "')"
set rsquery = conDB.Execute(SQL1)
set rsquery = nothing


Response.Redirect "galeria.asp?acao=3&opcao=1&text=Img_Inserido&id="&lc_id&""

End If

Link para o comentário
Compartilhar em outros sites

2 respostass a esta questão

Posts Recomendados

  • 0

Bareta desculpe a sumida, estive fora e não pude ver as menssagens, consegui solucionar o problema meu codigo ficou assim.

Case "INCLUIR_IMAGEM"
'Pega o Caminho da Pasta Imagens
Set rs = Dados_Gerais("")
lc_diretorio = rs("picture")
rs.Close 

Set Upload = Server.CreateObject("Persits.Upload")

'==============================================================================
'LIMITA O TAMANHO DO ARQUIVO PARA 500KB
'==============================================================================
Upload.SetMaxSize 500000, True

Count = Upload.Save (lc_diretorio)

If Err.Number = 8 Then

                  response.write "<table width=100% height=85 border=0 cellspacing=0 cellpadding=0>"
                  response.write "<td align=center valign=middle class=Nomes_Forms>"
                  response.Write "Esta imagem possui "& FormatNumber(File.Size,0) &" Kb<BR><BR>"
                  response.Write "O que exede o máximo permitido que é de 500 Kb por imagem<BR><BR>"
                  response.Write "<a href=java script:history.go(-1); class=Nomes_Forms_Normal>"
                  response.Write "&laquo; voltar ao formulário"
                  response.Write "</a>"
                  response.write "</td>" 
                  response.write "</table>"

Response.End
Else
'==============================================================================
Set File = Upload.Files(1)

If File.ImageType <> "UNKNOWN" Then


lc_id = Upload.form("txt_id")
lc_galeria = Upload.form("txt_galeria")
lc_legenda = Trim(Upload.form("txt_legenda"))

lc_link = Right(File.ExtractFileName,4)
lc_diahora = day(now) & month(now) & year(now) & hour(now) & minute(now) & second(now)
lc_foto = lc_cliente & lc_id & lc_diahora & lc_link

Rem Redimencionando a Imagem

        Set Jpeg = Server.CreateObject("Persits.Jpeg")
        
        Jpeg.Open (File.Path)
        
        if Jpeg.Width > Jpeg.Height then
            intXSize = 90
            intYSize = (intXSize / Jpeg.Width) * Jpeg.Height
        else
            intYSize = 90
            intXSize = (intYSize / Jpeg.Height) * Jpeg.Width
        end if
        
        Jpeg.Width = intXSize
        Jpeg.Height = intYSize
        
        'Jpeg.Sharpen 1, 150
        
        Jpeg.Save lc_diretorio & "P" & lc_foto
        
        Set Jpeg = nothing
        
Rem Redimencionando a Imagem

        Set Jpeg = Server.CreateObject("Persits.Jpeg")
        
        Jpeg.Open (File.Path)
        
        if Jpeg.Width > Jpeg.Height then
            intXSize = 170
            intYSize = (intXSize / Jpeg.Width) * Jpeg.Height
        else
            intYSize = 170
            intXSize = (intYSize / Jpeg.Height) * Jpeg.Width
        end if
        
        Jpeg.Width = intXSize
        Jpeg.Height = intYSize
        
        'Jpeg.Sharpen 1, 150
        
        Jpeg.Save lc_diretorio & "M" & lc_foto
        
        Set Jpeg = nothing
        
Rem Redimencionando a Imagem

        Set Jpeg = Server.CreateObject("Persits.Jpeg")
        
        Jpeg.Open (File.Path)
        
        if Jpeg.Width > Jpeg.Height then
            intXSize = 449
            intYSize = (intXSize / Jpeg.Width) * Jpeg.Height
        else
            intYSize = 449
            intXSize = (intYSize / Jpeg.Height) * Jpeg.Width
        end if
        
        Jpeg.Width = intXSize
        Jpeg.Height = intYSize
        
        'Jpeg.Sharpen 1, 150
        
        Jpeg.Save lc_diretorio & "G" & lc_foto
        
        Set Jpeg = nothing

Set Upload = Nothing

' deleta a imagem original do servidor            
   Set imagem = CreateObject("Scripting.FileSystemObject")
   If (imagem.FileExists(lc_diretorio&File.FileName)) Then
      imagem.DeleteFile(lc_diretorio&File.FileName)
   end if         
   Set imagem = Nothing


'Se não existe insere no banco de dados
SQL1 = "INSERT INTO tbl_foto (galeria, imagem, legenda) VALUES ('" & lc_id & "','" & lc_foto & "','" & lc_legenda & "')"
set rsquery = conDB.Execute(SQL1)
set rsquery = nothing


Response.Redirect "galeria.asp?acao=3&opcao=1&text=Img_Inserido&id="&lc_id&""

  End If
End If

Link para o comentário
Compartilhar em outros sites

Participe da discussão

Você pode postar agora e se registrar depois. Se você já tem uma conta, acesse agora para postar com sua conta.

Visitante
Responder esta pergunta...

×   Você colou conteúdo com formatação.   Remover formatação

  Apenas 75 emoticons são permitidos.

×   Seu link foi incorporado automaticamente.   Exibir como um link em vez disso

×   Seu conteúdo anterior foi restaurado.   Limpar Editor

×   Você não pode colar imagens diretamente. Carregar ou inserir imagens do URL.



  • Estatísticas dos Fóruns

    • Tópicos
      152,1k
    • Posts
      651,8k
×
×
  • Criar Novo...