Imagination is all on you.
If I am bored, I can spin the most wonderful daydreams. These come neither from good angels, bad angels, the devil or God....they come from my own musings.
The only outside influence might be a subtle suggestion on which path those thoughts/imaginations take. When impure thoughts occur, evil may try to encourage them and help you get "lost" in them...however, goodness will try to help you stop these thoughts, and think of something pure and harmless.
Temptation...well, that does not come from God. Remember, it was the devil that tempted Christ in the desert, not the other way around.
When we pray "and lead us not in to temptation", in the Lord's prayer, we do not mean that God gives us this temptation, but, we ask that He helps us avoid it.
In other words, if I am an alcoholic, and being at my friend's birthday party will tempt me to start drinking again, I ask that God help me avoid this party....perhaps my friend will decide not to serve liquor, perhaps my friend will cancel the party, perhaps my friend will simply forget to invite me.
Temptation does not come from God, but, He can certainly help us avoid it.