I found a way to remove the BOM (or - at least the question mark disappeared when I did so.) Here is the vbscript code:
Code: Select all
' Input is Unicode text and filePath is path to the image file we wish to create. First we create a utf-8 file
' named the same as the image file and then we use the utf-8 file as an input to when creating the image file.
Function writeUnicodeADODB(txtInput,filePath)
' Create and open stream
Dim objStream
Set objStream = CreateObject("ADODB.Stream")
objStream.Open
'Reset the position and indicate the charactor encoding
objStream.Position = 0
objStream.Charset = "UTF-8"
'Write to the steam
objStream.WriteText txtInput
'Save the stream to a file
filePath = filePath & ".txt"
objStream.SaveToFile filePath, 2 ' overwrite if exists
' Return filepath with an @ so that imagemagick understands that it's a file
writeUnicodeADODB = "@" & RemoveBOM(filePath)
' Kill stream
Set objStream = Nothing
End Function
' Removes the Byte Order Mark - BOM from a text file with UTF-8 encoding
' The BOM defines that the file was stored with an UTF-8 encoding.
Public function RemoveBOM(filePath)
' Create a reader and a writer
Dim writer,reader, fileSize
Set writer = CreateObject("Adodb.Stream")
Set reader = CreateObject("Adodb.Stream")
' Load from the text file we just wrote
reader.Open
reader.LoadFromFile filePath
' Copy all data from reader to writer, except the BOM
writer.Mode=3
writer.Type=1
writer.Open
reader.position=5
reader.copyto writer,-1
' Overwrite file
writer.SaveToFile filePath,2
' Return file name
RemoveBOM = filePath
' Kill objects
Set writer = Nothing
Set reader = Nothing
end function
As you can see, I first create the text file, based on the input, and I also set the character set to UTF-8. Then, before returning the file path to imagemagick, I run the file through RemoveBOM(filePath). the RemoveBOM function reads the text file, sets it's position to 5 and then copies everything from position five to another stream, which I again save by overwriting the text file we just read.
For any other that read this post, you will now see that my previously linked graphics file now display correctly:
The code I would use in vbscript to utilize these functions would be:
Code: Select all
strResult = img.Convert( _
"-size", "200x200", _
"-font", "Arial-Bold", _
"-pointsize", "12", _
"-fill", "#B6B6B6", _
"-annotate", "0x0+25+18", writeUnicodeADODB(UCase(sText), strDefaultPath & "top_" & sFilename), _
"-trim", _
strDefaultPath & "template.png", _
strDefaultPath & "top_" & sFilename)
Thanks for your help!
Kind regards,
nitech