I think you want this to be a `lazy val`, that way it is only evaluated once, `def` gets evaluated every time (and this always returns the same value).

    lazy val gif = { 
        ...
    }