I need a clearing please, I would like to know the most efficient and fastest way to display an image in a html page. runs between loading the remote image by downloading with file_get_contents and then converting to base64, or downloading with cURL and then converting to base64 or to simply passing the raw url in the img tag..
php code: - base64 with file_get_contents
$arrContextOptions=array("ssl"=>array("verify_peer"=>false,"verify_peer_name"=>false,));
$type_ext = pathinfo($image_path, PATHINFO_EXTENSION);
$imgData = file_get_contents($image_path, false, stream_context_create($arrContextOptions));
$imgBase64Data = base64_encode($imgData);
$imageData = 'data:image/'.$type_ext.';base64,' .$imgBase64Data;
$sizes = getimagesize($imageData);
-base64: cURL
$url = IMAGE_URL;
$ch = curl_init();
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 100);
$data = curl_exec($ch);
curl_close($ch);
$imageData = base64_encode($this->curl_get_contents($data));
$mime_types = array(
'gif' => 'image/gif',
'jpg' => 'image/jpg',
'jpeg' => 'image/jpeg',
'png' => 'image/png',
'bmp' => 'image/bmp'
);
$ext = pathinfo($image, PATHINFO_EXTENSION);
if (array_key_exists($ext, $mime_types)) {
$a = $mime_types[$ext];
}
echo "<img src='data: '.$a.';base64,'.$imageData/>";
-raw url
echo "<img src='IMAGE_URL'/>";
thank for all help