public function saveIconFromElggFile(ElggEntity $entity, ElggFile $file, $type = 'icon', array $coords = array())
{
if (!$file->exists()) {
throw new InvalidParameterException(__METHOD__ . ' expects an instance of ElggFile with an existing file on filestore');
}
$tmp_filename = time() . pathinfo($file->getFilenameOnFilestore(), PATHINFO_BASENAME);
$tmp = new ElggFile();
$tmp->owner_guid = $entity->guid;
$tmp->setFilename("tmp/{$tmp_filename}");
$tmp->open('write');
$tmp->close();
copy($file->getFilenameOnFilestore(), $tmp->getFilenameOnFilestore());
$tmp->mimetype = (new MimeTypeDetector())->getType($tmp->getFilenameOnFilestore(), $file->getMimeType());
$tmp->simpletype = elgg_get_file_simple_type($tmp->mimetype);
$result = $this->saveIcon($entity, $tmp, $type, $coords);
$tmp->delete();
return $result;
}