home *** CD-ROM | disk | FTP | other *** search
/ Australian Personal Computer 2004 July / APC0407D2.iso / workshop / onlineco / files / ImageMagick-6.0.1-Q16-windows-dll.exe / {app} / ImageMagickObject / Tests / ArrayTest.vbs next >
Encoding:
Text File  |  2003-04-03  |  3.5 KB  |  100 lines

  1. Option Explicit
  2.  
  3. 'On Error Resume Next
  4. Const ERROR_SUCCESS = 0
  5.  
  6. Dim img
  7. Dim myarray(1)
  8. Dim output(1)
  9. Dim persist(2)
  10. Dim info
  11. Dim msgs
  12. Dim elem
  13. Dim sMsgs
  14.  
  15. 'While 1
  16. '
  17. ' This is a complex example of how to work with images as blobs
  18. ' as well as how to do lossless embedding of textual information
  19. ' into an existing JPEG image.
  20. '
  21. Set img = CreateObject("ImageMagickObject.MagickImage.1")
  22. '
  23. ' Writing an image out to a VBSCRIPT array as a blob requires a
  24. ' way to tell IM what image format to use. The way this is done
  25. ' is to stuff the magick type into the array that will be used
  26. ' to store the results.
  27. '
  28. myarray(0)="8BIM:"
  29. '
  30. ' This command says to take a null input image and load some 8BIM
  31. ' format text data into it as a profile. Then just send the null
  32. ' image to the output as 8BIM binary format. Pretty funky stuff I
  33. ' admit.
  34. '
  35. msgs = img.Convert("null:","-profile","8BIMTEXT:iptctext.txt",myarray)
  36. 'If Err.Number <> ERROR_SUCCESS Then ShowError: WScript.Quit
  37. MsgBox "array: " & (ubound(myarray) - lbound(myarray) + 1)
  38. '
  39. ' Now that we have the binary 8BIM data in our array as a blob we
  40. ' can stuff it into a JPEG. You could just do that with the normal
  41. ' convert -profile commmand, but if the input image is a JPEG, it
  42. ' would decompress the JPEG and recompress is, which is a quality
  43. ' hit. To avoid that we use a special feature and load both our
  44. ' text info as well as out input JPEG into another NULL image as
  45. ' profiles. The special APP1JPEG profile tells IM to embed the text
  46. ' into the JPEG losslessly. We then store the result into another
  47. ' output array marked as APP1. This essentially just send the data
  48. ' stored in the APP1 profile out untouched. The net result is a
  49. ' completely unharmed JPEG with new text data embedded in it.
  50. '
  51. output(0)="APP1:"
  52. msgs = img.Convert("null:","-profile",myarray,"-profile","APP1JPEG:bill_meets_gorilla_screen.jpg",output)
  53. 'If Err.Number <> ERROR_SUCCESS Then ShowError: WScript.Quit
  54. MsgBox "output: " & (ubound(output) - lbound(output) + 1)
  55. '
  56. ' Last we want to save our output array into a disk file, which we
  57. ' could do with standard VBS file techniques, but we can also do it
  58. ' with convert directly - again using the APP1 profile type to both
  59. ' read the data and also to write it out to disk. This step is here
  60. ' to show how to force convert to use a specific image type for a
  61. ' blob. Normally convert would automatically detect the type and it
  62. ' would notice that this is a JPEG and decompress it. We don't want
  63. ' that in this case.
  64. '
  65. persist(0)="APP1:"
  66. persist(1)=output
  67. msgs = img.Convert("null:","-profile",persist,"APP1:bill_meets_gorilla_screen_iptc.jpg")
  68. '
  69. ' The following statements are the sequence you would need to free
  70. ' the memory being used by this sequence. It is not really needed
  71. ' by this example, but if you are writing some kind of loop were a
  72. ' number of images are being processed, it becomes very important to
  73. ' free memory, or you will leak and eventually crash - or worse just
  74. ' degrade the resources of the rest of the system.
  75. Set img=Nothing
  76. Erase persist
  77. myArray = Empty
  78. Redim myarray(1)
  79. output = Empty
  80. Redim output(1)
  81. 'Wend
  82. WScript.Quit(0)
  83.  
  84. Sub ShowError
  85.   sMsgs = ""
  86.   If BasicError(Err.Number) > 5000 Then
  87.     msgs = img.Messages
  88.     If isArray(msgs) Then
  89.       For Each elem In msgs
  90.         sMsgs = sMsgs & elem & vbCrLf
  91.       Next
  92.     End If
  93.   End If
  94.   WScript.Echo Err.Number & ": " & Err.Description & vbCrLf & sMsgs
  95. End Sub
  96.  
  97. Function BasicError(e)
  98.   BasicError = e And &HFFFF&
  99. End Function
  100.