我尝试运行我的PHP脚本时出现500内部服务器错误

时间:2015-03-04 00:15:07

标签: php tesseract

当它试图运行这个php脚本时

<?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>";
}

?>

当我使用xampp在我的计算机上测试它时,它可以正常工作但是当我尝试在我的服务器上运行它时,它不起作用。我和ImageMagick一起安装了Tesseract,我的所有php文件都设置为775,但我仍然感觉到内部服务器错误,因为我错过了依赖,但老实说我不知道​​哪些错误。谢谢你的帮助!

问题:我正在试图弄清楚如何解决我的内部服务器错误

1 个答案:

答案 0 :(得分:1)

  第134行的test.php中的

PHP Parse错误:语法错误,意外')'

此行还有一个)

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

应该是

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