SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    Currently Occupied; Till Sunda Andrew-J2000's Avatar
    Join Date
    Aug 2001
    Location
    London
    Posts
    2,475
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Is Graphic Corrupted?

    Is it possible to validate whether a graphic is corrupt? I have roughly 500 graphics being pulled out of a database, and I need to check whether they are corrupt and flag them if so. Unfortunately, I do not have any CRC or a Hash of the physical files, before they were uploaded.

    Code:
     
     Function AscAt(s, n)
      AscAt = Asc(Mid(s, n, 1))
     End Function
     
     Function HexAt(s, n)
      HexAt = Hex(AscAt(s, n))
     End Function
     
     Function isHex(c)
      If inStr("0123456789ABCDEFabcdef", c) <> 0 Then
       isHex = true
      Else
       ishex = false
      End If
     End Function
    
     Function HexToDec(cadhex)
      Dim n, i, ch, decimal
      decimal = 0
      n = Len(cadhex)
      For i=1 To n
      ch = Mid(cadhex, i, 1)
      If isHex(ch) Then
      decimal = decimal * 16
      If isDigit(c) Then
      decimal = decimal + ch
      Else
      decimal = decimal + Asc(uCase(ch)) - Asc("A")
      End If
      Else
      HexToDec = -1
      End If
      Next
      HexToDec = decimal
     End Function
     
     HW = Array("","")
     Set ts = FS.OpenTextFile(Server.MapPath("PAULA2.jpg"), 1)
     s = Right(ts.Read(167), 4)
     HW(0) = HexToDec(HexAt(s,3) & HexAt(s,4))
     HW(1) = HexToDec(HexAt(s,1) & HexAt(s,2))
     ts.Close
     Response.Write "Real: "& HW(0) & "x" & HW(1) & "<br />"& "<br />"
    If the above throws an error on ch, providing it is a jpg, would this indicate that the graphic would be corrupt? Is there a better alternative to validate this?
    Attached Images Attached Images

  2. #2
    SitePoint Wizard gRoberts's Avatar
    Join Date
    Oct 2004
    Location
    Birtley, UK
    Posts
    2,439
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Although its off topic, in your pubbing and clubbing pictures, is that Mr Smiths in warrington? Gav


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •