Reputation: 11
I am trying to scan a answer sheet and I am getting the list of errors on server as this code is part of batch job process.
my code is:
global $CFG;
//if ($x >= imagesx($this->image) or $x >= imagesy($this->image)) { // point is out of range
if ($x > imagesx($this->image) or $x > imagesy($this->image)) {
return false;
}
$rgb = imagecolorsforindex($this->image, imagecolorat($this->image, $x, $y));
$gray = $rgb['red'] + $rgb['green'] + $rgb['blue'];
if ($gray > $this->papergray) {
return false;
} else {
return true;
}
the error is in line:
$rgb = imagecolorsforindex($this->image, imagecolorat($this->image, $x, $y));
And error is:
Notice: imagecolorat(): 1520,-416 is out of bounds in C:\inetpub\wwwroot\elms\mo d\offlinequiz\report\rimport\scanner.php on line 1090
Notice: imagecolorat(): 1520,-415 is out of bounds in C:\inetpub\wwwroot\elms\mo d\offlinequiz\report\rimport\scanner.php on line 1090
Notice: imagecolorat(): 1520,-416 is out of bounds in C:\inetpub\wwwroot\elms\mo d\offlinequiz\report\rimport\scanner.php on line 1090
(Cont ....)
Upvotes: 1
Views: 121
Reputation: 360742
Typo:
if ($x > imagesx($this->image) or $x > imagesy($this->image)) {
^---------^
You'd doing width-width/width-height comparisons, instead of width-width/heigh-height.
Most likely if you have $y
for the indicated var, you'd never get error, as your negative $y would obviously never be larger than the image's height.
Upvotes: 2
Reputation: 3450
You should also check that $x and $y are >0. In the error messages $y is negative.
Upvotes: 0