Upload a contact image via the API
Contact Image URL is directly stored in civicrm_contact table, so I think if you have the URL which can display an image, you should be directly able to use the contact create API as below -

$result = civicrm_api3('Contact', 'create', array(
  'contact_type' =&gt; "Individual",
  'first_name' =&gt; "first",
  'last_name' =&gt; "last",
  'image_URL' =&gt; "&lt;url&gt;",
));


If you're on version &lt; 5.0, the contact summary page will render the image only iff the URL is in form of http://site-name/civicrm/contact/imagefile?photo=imageName.jpg and your image file should be present in your custom file upload directory.

There is now a patch(included in version 5.0) which allows the contact summary page to display any URL image irrespective of the photo param in the URL.

If you want to download a copy of a remote image to your local file system and use that, you could do something along the lines of:

$contactId = 123;
$imageName = 'jitendra.jpg';
$path = Civi::paths()-&gt;getPath(Civi::settings()-&gt;get('customFileUploadDir')) . $imageName;
file_put_contents($path, file_get_contents('https://i.stack.imgur.com/yjnic.jpg'));
civicrm_api3('Contact', 'create', [
  'id' =&gt; $contactId,
  'image_URL' =&gt; CRM_Utils_System::url('civicrm/contact/imagefile', ['photo' =&gt; $imageName], true)
]);