Search code examples
phpphp-gd

Check file is empty imagecreatefromgif - php


I am displaying image from file using PHP. My code looks like this

$image = @imagecreatefromgif(../ProfileIcons/".$use);

$text_color = imagecolorallocate($image, $r, $g, $b);
imagestring($image,$font_size,14,4, $code, $text_color);

header('Content-Type: image/gif');
$kk = imagegif($image);

imagedestroy($image);

Here how do i check if the image present in ProfileIcons/ is empty?

I have to put a condition such that

if (image is present in `ProfileIcons/`) 

   $image = @imagecreatefromgif(../ProfileIcons/".$use);

else (image is not present in the folder)

   $image = Show default image

How to achieve this?


Solution

  • try looking into file_exists

    if (file_exists($filePath)) {
    // process image
    } else {
    // use default image
    }