Your web server supports using php GD methods.
Your web server does NOT allow the IP Cameras port to be opened using php Curl methods.

Double check that your IP Camera is online and that the syntax in $ipcam_url is correct. If it is?
Then your web server, is not allowing your IP Cameras port to be opened as an Outbound Port by both php Curl and php GD methods.

If you use a web Hosting Service then you need to make a request that your Hosting Service
allows you to access the Outbound Port for your IP Camera using both php Curl and php GD methods.

If your Hosting Service refuses this request?
Then to use this php script. You will need to change your IP Cameras port to be port 80.
Please also change your IP Cameras port forwarding setup to use port 80 as well. If you do this.

If you run you own web server? Please allow your web server to open your IP cameras port using both php Curl and php GD methods