0

Hello buddy, im getting some warning like this:

Warning: file_get_contents() [function.file-get-contents]: Filename cannot be empty in /home/a8150490/public_html/index.php on line 4

Warning: imagecreatefromstring() [function.imagecreatefromstring]: Empty string or invalid image in /home/a8150490/public_html/ocrbreaker.php on line 5

Warning: imagesx(): supplied argument is not a valid Image resource in /home/a8150490/public_html/ocrbreaker.php on line 52

Warning: imagesy(): supplied argument is not a valid Image resource in /home/a8150490/public_html/ocrbreaker.php on line 53

ocrbreaker.php:

<?php
  error_reporting(E_ALL);
  class OCRbreaker {
    function read($data) {
        $orig  = imagecreatefromstring($data);
        $letter_num = 2;

        $pos = array("0","1","2","3","4","5","6","7","8","9","a","b","c","d","e","f");
        $code = '';
        $lbl = "";
        $hasil = array();
        foreach ($pos as $p1) {
                foreach ($pos as $p2) {
                        $lbl = $p1.$p2;
                        $gbr = $this->gambar($lbl);
                        $skor = $this->beda($orig, $gbr);
                        $hasil[$lbl] = $skor;
                }
        }
        asort($hasil);
        foreach ($hasil as $k=>$v) { $kode = $k; break; }
        return $kode;
  }

  function ketengah($image, $image_width, $string, $font_size, $y, $color) {
        $text_width = imagefontwidth($font_size)*strlen($string);
        $center = ceil($image_width / 2);
        $x = $center - (ceil($text_width/2));
        ImageString($image, $font_size, $x, $y, $string, $color);
  }
  function gambar($teks) {
        $width = 30;
        $height = 20;

        $image = ImageCreate($width, $height);
        $black = ImageColorAllocate($image, 0, 0, 0);
        $white = ImageColorAllocate($image, 255, 255, 255);
        $grey = ImageColorAllocate($image, 200, 200, 200);
        ImageFill($image, 0, 0, $white);
        $this->ketengah($image, $width, $teks, 3, 3, $black);
        ImageRectangle($image,0,0,$width-1,$height-1,$grey);
        return $image;
  }
  function gambar_canvas($teks) {
        $img = $this->gambar($teks);
        header("Content-Type: image/jpeg");
        ImageJpeg($img);
        ImageDestroy($img);
  }

  function beda($i1, $i2) {
        $sx1 = imagesx($i1);
        $sy1 = imagesy($i1);

        if ($sx1 !== imagesx($i2) || $sy1 !== imagesy($i2)) {
            return 100;
        }

        $diffi = imagecreatetruecolor($sx1, $sy1);
        $green = imagecolorallocate($diffi, 0, 255, 0);
        imagefill($diffi, 0, 0, imagecolorallocate($diffi, 0, 0, 0));

        $different_pixels = 0;

        for ($x = 0; $x < $sx1; $x++) {
            for ($y = 0; $y < $sy1; $y++) {

                $rgb1 = imagecolorat($i1, $x, $y);
                $pix1 = imagecolorsforindex($i1, $rgb1);

                $rgb2 = imagecolorat($i2, $x, $y);
                $pix2 = imagecolorsforindex($i2, $rgb2);

                if ($pix1 !== $pix2) {
                    $different_pixels++;
                    imagesetpixel($diffi, $x, $y, $green);
                }

            }
        }

        if (!$different_pixels) {
            return 0;
        } else {
            $total = $sx1 * $sy1;
            return number_format(100 * $different_pixels / $total, 2);
        }
  }
}
?>

index.php:

<?
  include_once('ocrbreaker.php');
  $ocr = new OCRbreaker();
  $tes = $ocr->read(file_get_contents($_GET["a"]));
  echo $tes;

  exit;
?>

<img src="http://m.kaskus.us/captcha/1c839f6980f221c6ec5b0a1fc4246ed7/1"/>&nbsp;
<img src="http://localhost/gambar.php?teks=ed"/>

Or maybe you can help me to fix these file?
Here is the file, please download: http://www.4shared.com/file/2ctsQd9X/THE_FILES.html
Thanks before, I appreciate your help.

2
Contributors
3
Replies
4
Views
6 Years
Discussion Span
Last Post by diafol
0

> Only for Good PHP Programmer

Ok, so some of us are not worthy to answer you question eh?
I will answer it here, but it's only for good cipherists. Perhaps YOU are not worthy my dear twitah!

tqhueerrey'sstnroipnagr.admoent'etrbiendtahfet

0

With "A good programmer" title like that, im just trying to pull a programmer to see this thread. Just that, not more.

0

We'd all like to get the best programmers on DW to answer our questions. I don't think that a title like this helps. The solution is trivial, a beginner-intermediate programmer should spot the problem. However, you'll probably have to wait for the big fishes to arrive. Unless you can work out the first answer of course! :)

Edited by diafol: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.