Use getimagesize()
it will return FALSE
if file corrupt otherwise if file is ok then it will return array containing file info like mime, height and width etc
, try below example
Example:
PHP
<?php
$fileName = 'https://horje.com/avatar.png'; //filepath
if(getimagesize($fileName) === false){
echo "Image is corrupted";
}
else{
echo "Image is ok";
}
?>
Example:
PHP
<?php
$fileName = 'https://horje.com/efeff.png'; //filepath
if(getimagesize($fileName) === false){
echo "Image is corrupted";
}
else{
echo "Image is ok";
}
?>
Here is simplae example of Title to Image in PHP
Example:
PHP
<?php
$title = 'Bangladesh is a Country';
$link = 'horje.com';
$cat = 'Blog Category';
$date = '05-Jan-2024';
$web = '[www.horje.com]';
$str1= $cat;
$str2= $link;
$str3= $title;
$str4= $date;
$str5= $web;
?>
<?php
// Create the size of image or blank image
$image = imagecreate(350, 250);
// Set the background color of image
$background_color = imagecolorallocate($image,70,130,180);
// Set the text color of image
$text_color = imagecolorallocate($image, 255, 255, 255);
// Function to create image which contains string.
imagestring($image, 5, 45, 80, $str1, $text_color);
imagestring($image, 3, 45, 100, $str3, $text_color);
imagestring($image, 3, 45, 120, $str2, $text_color);
imagestring($image, 3, 45, 140, $str4, $text_color);
imagestring($image, 3, 45, 160, $str5, $text_color);
header("Content-Type: image/png");
imagepng($image);
imagedestroy($image);
?>
I think that it should be.
Example:
PHP
<?php
function getDataURI($imagePath) {
$finfo = new finfo(FILEINFO_MIME_TYPE);
$type = $finfo->file($imagePath);
return 'data:' . $type . ';base64,' . base64_encode(file_get_contents($imagePath));
}
// Use the above function like below:
echo '<img src="' . getDataURI('https://horje.com/avatar.png') . '" alt="">';
echo '<img src="' . getDataURI('https://horje.com/avatar.png') . '" alt="">';
?>
See the example.
Example:
PHP
<?php
$html = ' <div class="itemer">
<span class="pointer" onclick="z49()">
<center>
</br>
<img src="https://website.sitelop.com/small/amazon.cn/icon.jpg" alt="Amazon.com. Spend less. Smile more." style="width:36px;height:36px; border-radius: 20%;" >
amazon.cn</center>
</span>
</div>
<div class="itemer">
<span class="pointer" onclick="z50()">
<center>
</br>
<img src="https://website.sitelop.com/small/cnn.com/icon.jpg" alt="Breaking News, Latest News and Videos | CNN" style="width:36px;height:36px; border-radius: 20%;" >
cnn.com</center>
</span>
</div>';
$dom = new DOMDocument();
$dom->loadHTML(mb_convert_encoding($html, 'HTML-ENTITIES', 'UTF-8'));
$images = $dom->getElementsByTagName('img');
foreach ($images as $image) {
$src = $image->getAttribute('src');
$type = pathinfo($src, PATHINFO_EXTENSION);
$data = file_get_contents($src);
$base64 = 'data:image/' . $type . ';base64,' . base64_encode($data);
$image->setAttribute("src", $base64);
}
$html = $dom->saveHTML();
echo $html;
?>