-1

When it try to run this php script

<?php
require_once 'TesseractOCR/TesseractOCR.php';

require_once 'aws_signed_request.php';

define("public_key", "****");
define("private_key", "****");
define("associate_tag", "****");

if (isset($_GET['ASIN']))
{
$ASIN = $_GET['ASIN'];
$link = "http://charts.camelcamelcamel.com/us/" . $ASIN . "/sales-rank.png?force=1&zero=0&w=400&h=400&legend=1&ilt=1&tp=1m&fo=0&lang=en";
$localurl = "../imgs/" . $ASIN . ".png";
$slocalurl = "../imgs/" . $ASIN . "-2.png";
$highrank = createSession($link, $localurl, 1);
$lowrank = createSession($link, $slocalurl, 2);
$info = ping_amazon($ASIN);
generate_response($info[0], $info[1], $lowrank, $highrank);
}
else
{
echo ('NO-ASIN');
}

function resize_and_crop($original_image_url, $thumb_image_url, $thumb_w, $thumb_h, $quality = 75)
{
$original = imagecreatefrompng($original_image_url);
if (!$original) return FALSE;
list($original_w, $original_h) = getimagesize($original_image_url);
$thumb_w_resize = $thumb_w;
$thumb_h_resize = $thumb_h;
if ($original_w > $original_h)
    {
    $thumb_h_ratio = $thumb_h / $original_h;
    $thumb_w_resize = (int)round($original_w * $thumb_h_ratio);
    }
  else
    {
    $thumb_w_ratio = $thumb_w / $original_w;
    $thumb_h_resize = (int)round($original_h * $thumb_w_ratio);
    }

if ($thumb_w_resize < $thumb_w)
    {
    $thumb_h_ratio = $thumb_w / $thumb_w_resize;
    $thumb_h_resize = (int)round($thumb_h * $thumb_h_ratio);
    $thumb_w_resize = $thumb_w;
    }

$thumb = imagecreatetruecolor($thumb_w_resize, $thumb_h_resize);
if (!imagecopyresampled($thumb, $original, 0, 0, 0, 0, $thumb_w_resize, $thumb_h_resize, $original_w, $original_h)) return FALSE;
$final = imagecreatetruecolor($thumb_w, $thumb_h);
$thumb_w_offset = 0;
$thumb_h_offset = 0;
if ($thumb_w < $thumb_w_resize)
    {
    $thumb_w_offset = (int)round(($thumb_w_resize - $thumb_w) / 2);
    }
  else
    {
    $thumb_h_offset = (int)round(($thumb_h_resize - $thumb_h) / 2);
    }

if (!imagecopy($final, $thumb, 0, 0, $thumb_w_offset, $thumb_h_offset, $thumb_w_resize, $thumb_h_resize)) return FALSE;
if (!imagepng($final, $thumb_image_url, $quality)) return FALSE;
return TRUE;
}

function createSession($link, $localurl, $imgtype)
{
copy($link, $localurl);
if ($imgtype == 1)
    {
    $sourceX = 125;
    $sourceY = 388;
    $sourceWidth = 110;
    $sourceHeight = 12;
    $destWidth = 110;
    $destHeight = 12;
    $destX = 0;
    $destY = 388;
    }
  else
    {
    $sourceX = 235;
    $sourceY = 388;
    $sourceWidth = 110;
    $sourceHeight = 12;
    $destWidth = 110;
    $destHeight = 12;
    $destX = 0;
    $destY = 388;
    }

$image = imagecreatefrompng($localurl);
$newImage = imagecreatetruecolor($sourceWidth, $sourceHeight);
$sNewImage = imagecreatetruecolor($sourceWidth, $sourceHeight);
imagecopyresampled($newImage, $image, 0, 0, $sourceX, $sourceY, $destWidth, $destHeight, $destWidth, $destHeight);
imagepng($newImage, $localurl, 9);
resize_and_crop($localurl, $localurl, $destWidth * 2, $destHeight * 2, 1);
imagedestroy($image);
imagedestroy($newImage);
$tesseract = new TesseractOCR($localurl);
$text = $tesseract->recognize();
$text = str_replace(" ", "", current(explode("(", $text)));
$text = str_replace(" ", "", current(explode("{", $text)));
$text = preg_replace('/[^0-9]+/', '', $text);
return $text;
}

function ping_amazon($ASIN)
{
$params = array(
    "Operation" => "ItemLookup",
    "IdType" => "ASIN",
    "ItemId" => $ASIN,
    "ResponseGroup" => "SalesRank,ItemAttributes"
);
$url = encode_info("com", $params, public_key, private_key, associate_tag);
$xml = simplexml_load_file($url);
$title = (string)$xml->Items->Item->ItemAttributes->Title;
$salesrank = (string)$xml->Items->Item->SalesRank;
$info = array(
    $title,
    $salesrank
);
return $info;
}

function generate_response($title, $salesrank, $lowrank, $highrank)
{
$average_rank = intval(($highrank + $lowrank) / 2));
header("Content-type: text/xml");
echo "<?xml version='1.0' encoding='UTF-8'?>\n";
echo "<Information>\n";
echo "<Title>" . $title . "</Title>\n";
echo "<SalesRank>" . $salesrank . "</SalesRank>\n";
echo "<LowRank>" . $lowrank . "</LowRank>\n";
echo "<HighRank>" . $highrank . "</HighRank>\n";
echo "<AverageRank>" . $average_rank . "</AverageRank>\n";
echo "</Information>";
}

?>

it works when I am testing it on my computer with xampp but when I try to run this on my server it doesn't work. I have Tesseract installed along with ImageMagick and all my php files are set to 775 but I still get an internal server error I feel like it's because i am missing dependencies but I honestly don't know which ones. Thanks for the help!

Question: I am trying to figure out how to fix my internal server error

Teirten
  • 61
  • 7

1 Answers1

1

PHP Parse error: syntax error, unexpected ')' in test.php on line 134

You have an extra ) on this line

$average_rank = intval(($highrank + $lowrank) / 2));

Should be

$average_rank = intval(($highrank + $lowrank) / 2);
Steve Robbins
  • 13,672
  • 12
  • 76
  • 124
  • Wow I feel stupid that fixed my problem but now I just gotta figure out how to get Tesseract to work on CentOS sorry for this bad question. – Teirten Mar 04 '15 at 00:43
  • Looks like you aren't the first on that front http://stackoverflow.com/questions/23792373/installing-tesseract-ocr-on-centos-6 – dudeman Mar 04 '15 at 00:48