0

I get multiples php errors in server log , the error show on 2 lines of my php code, However php script is working but it show these errors in server log.

PHP Notice:  Trying to access array offset on value of type null 
PHP Notice:  Undefined offset: 79
PHP Notice:  Undefined offset: 89
PHP Notice:  Undefined offset: 32 

Here i added the partial piece of my php code where error is showing:

function right2img($color,$text,$pos,$font,$fontxy,$im){
    $letters = imagecreatefromstring(base64_decode($font));
    $rgb = getRGB($color);
    $index = imagecolorexact($letters, 0, 0, 0);
    imagecolorset ($letters, $index, $rgb[0], $rgb[1], $rgb[2]);
    for($i=0;$i<strlen($text);$i++){
        $c = ord($text[$i]);
        imagecopy ($im, $letters, $pos, 5, $fontxy[$c]["x"], $fontxy[$c]["y"], $fontxy[$c]["w"], 5);
        $pos+= $fontxy[$c]["w"];
    }
    return $im;
}

The errors are came from these 2 lines of above code

    imagecopy ($im, $letters, $pos, 5, $fontxy[$c]["x"], $fontxy[$c]["y"], $fontxy[$c]["w"], 5);
    $pos+= $fontxy[$c]["w"];

Can't figure how to fix it. ....any help ?

0

1 Answer 1

1

The $fontxy might be null.
You have to check the valid index value for $fontxy.

if(isset($fontxy[$c]) && isset($fontxy[$c]["x"]) && isset($fontxy[$c]["y"])&& isset($fontxy[$c]["w"])){
imagecopy ($im, $letters, $pos, 5, $fontxy[$c]["x"], $fontxy[$c]["y"], $fontxy[$c]["w"], 5);
        $pos+= $fontxy[$c]["w"];
}
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks it solve the problem, no more errors are showing in server log :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.