dongnuo4594 2012-08-19 15:11
浏览 76
已采纳

颜色提取脚本 - ForEach错误

So I downloaded and edited a script off the internet to pull an image and find out the hex values it contains and their percentages:

The script is here:

<?php
$delta = 5;
$reduce_brightness = true;
$reduce_gradients = true;
$num_results = 5;

include_once("colors.inc.php");
$ex=new GetMostCommonColors();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<title>Colour Verification</title>

</head>
<body>
    <div id="wrap">
    <img src="http://www.image.come/image.png" alt="test image" />
    <?php
        $colors=$ex->Get_Color("http://www.image.come/image.png", $num_results, $reduce_brightness, $reduce_gradients, $delta);
        $success = true;
        foreach ( $colors as $hex => $count ) {
            if ($hex !== 'e6af23') {$success = false; }
        if ($hex == 'e6af23' && $count > 0.05) {$success = true; break;}
        }

        if ($success == true) { echo "This is the correct colour. Success!"; } else { echo "This is NOT the correct colour. Failure!"; }


?>
    </div>

</body>
</html>

Here is a pastebin link to the file colors.inc.php

http://pastebin.com/phUe5Pad

Now the script works absolutely fine if I use an image that is on the server, eg use /image.png in the Get_Color function. However, if I try and use an image from another website including a http://www.site.com/image.png then the script no longer works and this error appears:

Warning: Invalid argument supplied for foreach() in ... on line 22

Is anyone able to see a way that I would be able to hotlink to images because this was the whole point of using the script!

  • 写回答

2条回答 默认 最新

  • douwan4993 2012-08-19 15:39
    关注

    You must download a file to the server and pass its full filename to the method Get_Color($img) as $img parameter.

    So, you need to investigate another SO question: Download File to server from URL

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 运筹学排序问题中的在线排序
  • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
  • ¥30 求一段fortran代码用IVF编译运行的结果
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 lammps拉伸应力应变曲线分析
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥15 请问Lammps做复合材料拉伸模拟,应力应变曲线问题