Storing animated .gif images

Discussion in 'Ruby' started by Patrick Spence, Aug 17, 2006.

  1. The following code throws the error indicated in the code. Apparently
    this only appears to happen with animated gifs. Other image formats;
    jpg, etc., are ok. A VB version of this code, which also uses ADO, works
    w/o any problems.

    require 'win32ole'

    ADTYPETEXT = 0
    ADTYPEBINARY = 1

    ADSTATECLOSED = 0
    ADSTATEOPEN = 1
    ADSTATEEXECUTING = 4
    ADSTATEFETCHING = 8

    ADOPENKEYSET = 1
    ADLOCKOPTIMISTIC = 3

    begin

    imageFile = "dj.gif" #-- this is an animated gif!

    st = WIN32OLE.new("adodb.stream")
    st.Type = ADTYPEBINARY
    st.Open
    st.loadFromFile(imageFile)

    puts("Size of image file: #{st.size()} bytes")

    oCn = WIN32OLE.new("adodb.connection")
    oCn.open("Provider=sqloledb;Data Source=(local);Initial
    Catalog=xxxxx;Integrated Security=SSPI;")

    oRs = WIN32OLE.new("adodb.recordset")
    oRs.open("SELECT * FROM xxxx", oCn, ADOPENKEYSET, ADLOCKOPTIMISTIC)

    oRs.addNew()

    #-- store the name of the image file
    oRs.fields("imageFile").value = imageFile

    #-- throws the following error when the next line is executed
    =begin
    OLE error code:80040E21 in Provider
    Multiple-step OLE DB operation generated errors. Check each OLE DB
    status value, if available. No work was done.
    HRESULT error code:0x80020009
    Exception occurred.
    =end
    oRs.fields("imageBinary").value = (st.read().to_s())

    oRs.update()

    rescue Exception => ex

    puts("Exception: #{ex.message()}")

    ensure

    #-- close and release recordset and database objects
    unless oRs.nil?
    unless oRs.state == ADSTATECLOSED
    oRs.close
    end
    oRs = nil
    end

    unless oCn.nil?
    unless oCn.state == ADSTATECLOSED
    oCn.close
    end
    oCn = nil
    end

    unless st.nil?
    st.close()
    end

    end

    --
    Posted via http://www.ruby-forum.com/.
    Patrick Spence, Aug 17, 2006
    #1
    1. Advertising

  2. Patrick Spence wrote:
    > The following code throws the error indicated in the code. Apparently
    > this only appears to happen with animated gifs. Other image formats;
    > jpg, etc., are ok. A VB version of this code, which also uses ADO, works
    > w/o any problems.


    <*big* snip>

    I guess I've answered my own question... an animated gif file is
    actually *several* layered images. No bloody wonder I was getting the
    aforementioned error when I attempted to store it in the SQL Server
    table. On the brighter side of things, I've stumbled across a way to
    store and retrieve other binary files; specifically .jpg's, in a table,
    w/o resorting to using the ADODB.Stream object. If there's any interest,
    I'll post the code.

    --
    Posted via http://www.ruby-forum.com/.
    Patrick Spence, Aug 23, 2006
    #2
    1. Advertising

  3. Patrick Spence wrote:
    > I guess I've answered my own question... an animated gif file is
    > actually *several* layered images. No bloody wonder I was getting the
    > aforementioned error when I attempted to store it in the SQL Server
    > table. On the brighter side of things, I've stumbled across a way to
    > store and retrieve other binary files; specifically .jpg's, in a table,
    > w/o resorting to using the ADODB.Stream object. If there's any interest,
    > I'll post the code.


    That's not exactly correct. It's still only 1 file, and you couldn't
    split the file at several points and end up with whole images.

    An animated gif is indeed several image pieces in a single file, but
    there's no reason trying to store that file should break anything.
    There no 'EOF' markers or any crazy thing in the middle of the file.

    --
    Posted via http://www.ruby-forum.com/.
    William Crawford, Aug 23, 2006
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jeronimo Bertran

    Creating animated GIF dynamically

    Jeronimo Bertran, Nov 13, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    484
    Xin Huang [MSFT]
    Nov 14, 2003
  2. Shabam

    Animated GIF handling

    Shabam, Mar 5, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    343
    Shabam
    Mar 5, 2004
  3. =?Utf-8?B?S29lbiBIb29yZWxiZWtl?=

    reading an animated gif ...

    =?Utf-8?B?S29lbiBIb29yZWxiZWtl?=, Oct 9, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    518
    =?Utf-8?B?S29lbiBIb29yZWxiZWtl?=
    Oct 10, 2004
  4. =?Utf-8?B?QWw=?=

    Animated GIF affected by location.replace

    =?Utf-8?B?QWw=?=, Oct 12, 2004, in forum: ASP .Net
    Replies:
    3
    Views:
    7,263
    =?Utf-8?B?QWw=?=
    Oct 21, 2004
  5. Joe
    Replies:
    0
    Views:
    3,121
Loading...

Share This Page