Save user Icon from URL

How can I save a user icon by a image url?  Before I did something like this but doesn't seem to work on egg 2.3

$photo_url = http://mysite.com/image;

$icon_sizes = elgg_get_config('icon_sizes');

                $filehandler = new ElggFile();
                $filehandler->owner_guid = $single->guid;
                foreach ($icon_sizes as $size => $dimensions) {
                    $image = get_resized_image_from_existing_file(
                            $photo_url, $dimensions[0], $dimensions[1], $dimensions[2]
                    );

                    $image = get_resized_image_from_existing_file($photo_url, $dimensions['w'], $dimensions['h'], $dimensions['square'], 0, 0, 0, 0, $dimensions['upscale']);

                    $filehandler->setFilename("profile/{$single->guid}{$size}.jpg");
                    $filehandler->open('write');
                    $filehandler->write($image);
                    $filehandler->close();
                }