I know of imagecreatefromgif()
, imagecreatefromjpeg()
, and imagecreatefrompng()
but is there a way to create an image resource (for png preferably) from a url of any type of valid image? Or do you have to determine the file type and then use the appropriate function?
When I say url I mean something like http://sample.com/image.png
, not a data url
Maybe you want this:
Here's how it's done:
With some small modifications to
switch
same function is ready for web url's:After that you can use it with
http://www.tld/image.jpg
:Some proofs:
As you can read from official PHP manual function.imagecreatefromjpeg.php GD allows loading images from URLs that is supported by function.fopen.php, so there is no need to fetch image first and save it to file, and open that file.