Can you please guide me how can I convert an image from a URL to base64 encoding?
相关问题
- Views base64 encoded blob in HTML with PHP
- Laravel Option Select - Default Issue
- How to get the background from multiple images by
- PHP Recursively File Folder Scan Sorted by Modific
- Can php detect if javascript is on or not?
Easy:
bear in mind that this will enlarge the data by 33%, and you'll have problems with files whose size exceed your
memory_limit
.Here is an example using a cURL call.. This is better than the file_get_contents() function. Of course, use base64_encode()
Use also this way to represent image in base64 encode format... find PHP function
file_get_content
and next to use functionbase64_encode
and get result to prepare str as
data:" . file_mime_type . " base64_encoded string
. Use it in img src attribute. see following code can I help for you.I was trying to use this resource but kept getting an error, I found the code above worked perfectly.
Just replaced IMAGE URL HERE with the URL of your image - http://www.website.com/image.jpg
You can also do this via curl, just you need a path to an image file and pass it to the function given below..
Just in case you are (for whatever reason) unable to use
curl
norfile_get_contents
, you can work around: