How to load an image from a URL into a PHP script and encode it as a base64 string? -


i want fetch image url, resizing service, , convert base64 string consumption @ client side.

i use following code,

$imagepath = "www.xyz.com/resize/view.php?image=../pictures/abc.jpg&mode=crop&size=200x200"; $image = imagecreatefromstring(file_get_contents($imagepath)); $thumb_encoded = base64_encode($image); echo "<br>".$thumb_encoded; 

the $imagepath value, when opened in browser works fine. image displayed. when running script, php throws following error,

php warning: file_get_contents(www.xyz.com/resize/view.php?image=../../pictures/abc.jpg&\amp;mode=crop&\amp;size=200x200): failed open stream: no such file or directory in resizeimage.php on line 12

the & params in url needed $_get getting converted &\amp; while making request in php script. have tried urlencode() , htmlspecialchars($url) , html_entity_decode() , escape characters, in vain. same/similar issues. image wont load, url script queries wrong. can point out issue here , me?


Comments