PHP - 使用imagejpeg作为背景

I have loaded an image in a variable like this :

$img = imagecreatefromjpeg('my_image.jpg');

Now I want to use that image variable as a background for an html element. I tried this :

<div id="container" style="background:<?php imagejpeg($img);?>;"></div>

And I failed miserably. I don't know how to proceed.

I am not sure what's your ultimate goal, but why not do something like this:

$img = my_image.jpg;
<div id="container" style="background-image: url(<?=$img?>);"></div>

I think u failed because your code leaks an 'echo' statement:

<div id="container" style="background:<?php echo imagejpeg($img);?>;"</div>

should do the work :-)