如何使用base-64源创建Image对象?

I have a remote web page, on which I use CURL and DOMDocument to retrive the src attribute of an image.

I use the following code, mixing JS in a PHP echo

<?php 

$toEcho = "";
$toEcho .= // some stuff here...
$toEcho.="
<script>

    //I create the object
    var img = new Image();

    //I set the source with the PHP variable : I get an error because of unexpected token ":"
    img.src = $imgsrc;

</script>"
echo $toEcho;
?>

I checked the source, it is valid, and displays properly in my browser(s).

Where could this come from ?

Set the source like this:

img.src = '$imgsrc';