So if I understand it correctly, you want to use the value of a Javascript variable in a PHP function.
Unfortunately, that won't work. All javascript happens on the client side, i.e. in the browser. PHP is a server-side language, it all happens on the server.
Generally, what happens in the sequence of requests is:
- The client asks the server for a page;
- The server receives the request and looks for the PHP source to use;
- The server processes ALL the PHP code to valid HTML code that the browser can use.
- The server sends the finished HTML code to the client;
- The client's browser reads all of the HTML and interprets it, including inline javascript.
- The client side javascript gets executed.
As you can see, the server side code doesn't know about the Javascript or the variables defined in javascript, and the browser doesn't know anything about the PHP used to generate the page. If you have a Javascript object you need to use in PHP, there are really only 2 options:
- You do the object processing server-side completely, so instead of trying to find the image url in the javascript, you store and read it on the server side;
- You use an AJAX request to get the image url from the server to the client.