PHP save picture from url and convert .gif to .png

$picname = 'avatar'.uniqid().uniqid();

$ch = curl_init("https:".$picture->src);
$fp = fopen('/var/www/html/Python/users_avatar/'.$picname.'.gif', 'wb');
curl_setopt($ch, CURLOPT_FILE, $fp);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_exec($ch);
curl_close($ch);
fclose($fp);

imagepng(imagecreatefromstring(file_get_contents('/var/www/html/Python/users_avatar/'.$picname.'.gif')), '/var/www/html/topzapp/users_avatar/'.$picname.'.png');